solve-engine 2.26.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/{chunk-MTN53APQ.js → chunk-BCY2WY5P.js} +3 -3
  2. package/dist/{chunk-MTN53APQ.js.map → chunk-BCY2WY5P.js.map} +1 -1
  3. package/dist/{chunk-OPKJ2WWB.cjs → chunk-DFMAZ6XM.cjs} +3 -3
  4. package/dist/chunk-DFMAZ6XM.cjs.map +1 -0
  5. package/dist/{chunk-YS2OW75C.cjs → chunk-O5PO4D2A.cjs} +2 -2
  6. package/dist/{chunk-YS2OW75C.cjs.map → chunk-O5PO4D2A.cjs.map} +1 -1
  7. package/dist/chunk-PQFI55AC.js +3 -0
  8. package/dist/chunk-PQFI55AC.js.map +1 -0
  9. package/dist/{chunk-GQM6ICDM.js → chunk-REZQFPVX.js} +2 -2
  10. package/dist/{chunk-GQM6ICDM.js.map → chunk-REZQFPVX.js.map} +1 -1
  11. package/dist/{chunk-MCU7UYKG.js → chunk-UVHD7BBC.js} +3 -3
  12. package/dist/{chunk-MCU7UYKG.js.map → chunk-UVHD7BBC.js.map} +1 -1
  13. package/dist/{chunk-CQY23OF5.cjs → chunk-YSHWNCDH.cjs} +4 -4
  14. package/dist/{chunk-CQY23OF5.cjs.map → chunk-YSHWNCDH.cjs.map} +1 -1
  15. package/dist/{chunk-C5GEMKUY.cjs → chunk-ZPHUTCJ5.cjs} +3 -3
  16. package/dist/{chunk-C5GEMKUY.cjs.map → chunk-ZPHUTCJ5.cjs.map} +1 -1
  17. package/dist/constants.cjs +1 -1
  18. package/dist/constants.js +1 -1
  19. package/dist/engine.cjs +1 -1
  20. package/dist/engine.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/packages.cjs +1 -1
  24. package/dist/packages.js +1 -1
  25. package/dist/testing.cjs +2 -2
  26. package/dist/testing.js +1 -1
  27. package/dist/worker.cjs +2 -2
  28. package/dist/worker.js +1 -1
  29. package/package.json +1 -1
  30. package/dist/chunk-LMZDTQS5.js +0 -3
  31. package/dist/chunk-LMZDTQS5.js.map +0 -1
  32. package/dist/chunk-OPKJ2WWB.cjs.map +0 -1
@@ -1,3 +1,3 @@
1
- 'use strict';var chunkG2V33LFM_cjs=require('./chunk-G2V33LFM.cjs'),chunk7RC6RBS6_cjs=require('./chunk-7RC6RBS6.cjs'),chunkZDJTDFTR_cjs=require('./chunk-ZDJTDFTR.cjs'),chunkZSLVLMO5_cjs=require('./chunk-ZSLVLMO5.cjs'),chunkUURM7P3P_cjs=require('./chunk-UURM7P3P.cjs'),chunkZLRJ7TDP_cjs=require('./chunk-ZLRJ7TDP.cjs'),chunkQQHHZPEW_cjs=require('./chunk-QQHHZPEW.cjs'),chunkTMQ37JQY_cjs=require('./chunk-TMQ37JQY.cjs'),chunkTLG7VZRX_cjs=require('./chunk-TLG7VZRX.cjs'),chunk5TVI2UPZ_cjs=require('./chunk-5TVI2UPZ.cjs'),chunkFDKTESBC_cjs=require('./chunk-FDKTESBC.cjs'),chunkTPPM4QSS_cjs=require('./chunk-TPPM4QSS.cjs'),chunkE4HAKNBQ_cjs=require('./chunk-E4HAKNBQ.cjs'),chunkGJZIJK2Q_cjs=require('./chunk-GJZIJK2Q.cjs'),chunkZKFCKAIX_cjs=require('./chunk-ZKFCKAIX.cjs'),chunk6EYKVQT3_cjs=require('./chunk-6EYKVQT3.cjs'),chunkYBQOQTVL_cjs=require('./chunk-YBQOQTVL.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunkJ4LSAHCY_cjs=require('./chunk-J4LSAHCY.cjs'),chunkEZKR44MA_cjs=require('./chunk-EZKR44MA.cjs'),chunkGXO7TSXQ_cjs=require('./chunk-GXO7TSXQ.cjs');var Qu=/^\d{1,3}(\.\d{3}){2,}$/,qu=/^\d*\.\d*$/,Lt=class{constructor(){this.category="Arithmetic";}parse(e,o,r){let n,i=null,a=o.value;if(a.startsWith("0x")||a.startsWith("0X")){if(n=parseInt(a,16),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid hex literal: "${a}"`,{raw:a})}else if(a.startsWith("0b")||a.startsWith("0B")){if(n=parseInt(a.slice(2),2),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid binary literal: "${a}"`,{raw:a})}else if(a.startsWith("0o")||a.startsWith("0O")){if(n=parseInt(a.slice(2),8),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid octal literal: "${a}"`,{raw:a})}else if(Qu.test(a))n=parseFloat(a.split(".").join(""));else {let s=chunkS3DFU33X_cjs.a(e.getLocaleCode()),l=s.display.decimalSeparator,u=s.display.thousandsSeparator,c=a;u&&(c=c.split(u).join("")),l&&l!=="."&&(c=c.replace(l,".")),n=parseFloat(c),qu.test(c)&&(i=c);}if(i!==null){r.emitOpcode(16),r.emitString(i);return}r.emitOpcode(10),r.emitNumber(n);}};var he=class{constructor(e){this.opcode=e;this.category="Arithmetic";}parse(e,o,r){e.parseExpression(60,r),r.emitOpcode(this.opcode);}};var B=class{constructor(e,o,r=false){this.opcode=o;this.category="Arithmetic";this.bindingPower=e,this.rightBindingPower=r?e-1:e;}parse(e,o,r,n){e.parseExpression(this.rightBindingPower,n),n.emitOpcode(this.opcode);}};var vt=class{constructor(){this.category="Arithmetic";}parse(e,o,r){e.parseExpression(0,r);let n=1;for(;e.match("COMMA");)e.parseExpression(0,r),n++;e.consume("RPAREN"),n>1&&(r.emitOpcode(152),r.emitIndex(1),r.emitIndex(n));}};var Qe=class{constructor(){this.category="Arithmetic";}parse(e,o,r){let n=o.type==="PI"?Math.PI:Math.E;r.emitOpcode(10),r.emitNumber(n);}};var Zu={k:3,M:6,G:9,B:9,T:12},Ju={thousand:3,thousands:3,million:6,millions:6,mn:6,billion:9,billions:9,bn:9,trillion:12,trillions:12,tn:12},ec=/^\d+(\.\d+)?$/;function tc(t,e){let o=t.indexOf("."),r=o===-1?t:t.slice(0,o),n=o===-1?"":t.slice(o+1);n.length<e&&(n=n.padEnd(e,"0"));let i=r+n.slice(0,e),a=n.slice(e);return a?`${i}.${a}`:i}function Ma(t=65){return {name:"arithmetic:large-number-suffix",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT","UNIT"]}],match(e,o){let r=e[o];if(r.type!=="NUMBER"||!ec.test(r.text))return null;let n=e[o+1];if(!n||n.type!=="IDENT"&&n.type!=="UNIT")return null;let i=r.offset+r.text.length===n.offset,a=n.type==="UNIT"?void 0:Ju[n.value.toLowerCase()],s=i?Zu[n.value]??a:a;if(s===void 0)return null;let l=tc(r.text,s);return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b("NUMBER",l,e.slice(o,o+2))],ruleName:"arithmetic:large-number-suffix"}}}}var on={name:"solve-arithmetic",prefixParselets:{NUMBER:new Lt,LPAREN:new vt,PI:new Qe,E:new Qe,PLUS:new he(27),MINUS:new he(26),BIT_NOT:new he(36)},infixParselets:{PLUS:new B(chunkZDJTDFTR_cjs.a.Sum,20),AND_CONJ:new B(chunkZDJTDFTR_cjs.a.Conjunction,20),MINUS:new B(chunkZDJTDFTR_cjs.a.Sum,21),STAR:new B(chunkZDJTDFTR_cjs.a.Product,22),SLASH:new B(chunkZDJTDFTR_cjs.a.Product,23),MOD:new B(chunkZDJTDFTR_cjs.a.Product,24),CARET:new B(chunkZDJTDFTR_cjs.a.Exponent,25,true),TIMES_BY:new B(chunkZDJTDFTR_cjs.a.Product,22),MULTIPLY_BY:new B(chunkZDJTDFTR_cjs.a.Product,22),DIVIDE_BY:new B(chunkZDJTDFTR_cjs.a.Product,23),LSHIFT:new B(chunkZDJTDFTR_cjs.a.Shift,30),RSHIFT:new B(chunkZDJTDFTR_cjs.a.Shift,31),URSHIFT:new B(chunkZDJTDFTR_cjs.a.Shift,32),BIT_AND:new B(chunkZDJTDFTR_cjs.a.BitwiseAnd,33),BIT_OR:new B(chunkZDJTDFTR_cjs.a.BitwiseOr,34),BIT_XOR:new B(chunkZDJTDFTR_cjs.a.BitwiseXor,35)},normalizerRules:[Ma()]};var wt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){n.emitOpcode(10),n.emitNumber(100),n.emitOpcode(23),n.emitOpcode(74);}};var kt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){if(ba(e,"what")){e.consume(),this.parseWhatRate(e,n);return}this.parseWhatBase(e,n);}parseWhatRate(e,o){if(!e.match("PERCENT"))throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_PERCENT",'Expected "%" after "is what", as in "20 is what % of 200"');let r=rc(e);if(r===null){o.emitOpcode(74);return}e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),o.emitOpcode(23),r==="off"?(o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(2),o.emitOpcode(21)):r==="on"&&(o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(21)),o.emitOpcode(74);}parseWhatBase(e,o){if(e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),e.match("TO")){Da(e,"what",'"81 is 9 to what power"'),Da(e,"power",'"81 is 9 to what power"'),o.emitOpcode(51),o.emitIndex(Ua),o.emitIndex(1),o.emitOpcode(2),o.emitOpcode(51),o.emitIndex(Ua),o.emitIndex(1),o.emitOpcode(2),o.emitOpcode(23);return}let r=e.match("OF_WHAT")?"of":e.match("OFF_WHAT")?"off":e.match("ON_WHAT")?"on":null;if(r===null)throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_PREPOSITION",'Expected "of what", "off what" or "on what", as in "20 is 10% of what"');if(r==="of"){o.emitOpcode(23);return}o.emitOpcode(10),o.emitNumber(1),r==="off"?(o.emitOpcode(2),o.emitOpcode(21)):o.emitOpcode(20),o.emitOpcode(23);}},Ua=5;function ba(t,e){return (t.peek()?.text??"").toLowerCase()===e}function Da(t,e,o){if(!ba(t,e))throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_WORD",`Expected "${e}" here, as in ${o}`);t.consume();}function rc(t){if(t.match("OF"))return "of";let e=(t.peek()?.text??"").toLowerCase();return e==="off"||e==="on"?(t.consume(),e):null}var qe=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(2),n.emitOpcode(10),n.emitNumber(1),this.sign===1?n.emitOpcode(20):(n.emitOpcode(2),n.emitOpcode(21)),n.emitOpcode(22);}};function Va(t=68){return {name:"percentage:on-off",priority:t,shape:[{types:["PERCENT"]},{types:["IDENT"],values:["on","off"]}],match(e,o){if(e[o]?.type!=="PERCENT")return null;let r=e[o+1];if(r?.type!=="IDENT")return null;let n=(r.text??r.value??"").toLowerCase();return n!=="on"&&n!=="off"||(e[o+2]?.text??"").toLowerCase()==="what"?null:{consumed:2,replacement:[e[o],chunkZSLVLMO5_cjs.b(n==="on"?"PCT_ON":"PCT_OFF",n,[r])],ruleName:"percentage:on-off"}}}}var Bt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(22);}};var Mt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23);}};var Ze=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){n.emitOpcode(10),n.emitNumber(1),this.sign===1?n.emitOpcode(20):(n.emitOpcode(2),n.emitOpcode(21)),e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23);}};var Je=class{constructor(e){this.multiplier=e;this.category="Percentage";}parse(e,o,r){e.parseExpression(0,r);let n=e.peek();n&&(n.type==="IDENT"||n.type==="BY")&&e.consume(),r.emitOpcode(10),r.emitNumber(1),e.parseExpression(0,r),e.peek()?.type==="PERCENT"&&e.consume(),r.emitOpcode(this.multiplier>0?20:21),r.emitOpcode(22);}};var et=class{constructor(e){this.multiplier=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(2),n.emitOpcode(this.multiplier>0?20:21),n.emitOpcode(22);}};var Ut=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){if(o.type==="UNIT")return;let i=e.peek();if(i&&((i.type==="UNIT"||i.type==="IDENT")&&chunkJ4LSAHCY_cjs.b(i.value)||i.type==="IN")){e.consume(),n.emitOpcode(13),n.emitString(i.value),n.emitOpcode(84);return}e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(21),n.emitOpcode(74);}};var oc={one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12};function nc(t){if(t.type==="NUMBER"){let e=Number(t.value);return Number.isInteger(e)&&e>=0?e:null}return t.type==="IDENT"?oc[t.value.toLowerCase()]??null:null}var tt=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(2),n.emitOpcode(this.sign>0?20:21);let i=this.tryConsumeRepeat(e);i!==null&&(n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(25)),n.emitOpcode(22),this.consumeChainThen(e);}tryConsumeRepeat(e){let o=e.peek(),r=e.peekAt(1);if(!o||!r||r.type!=="STAR"||r.value.toLowerCase()!=="times")return null;let n=nc(o);return n===null?null:(e.consume(),e.consume(),n)}consumeChainThen(e){if(e.peek()?.type!=="THEN")return;let o=e.peekAt(1)?.type;(o==="PCT_UP"||o==="PCT_DOWN")&&e.consume();}};function Fa(t,e){let o=t[e];if(o?.type!=="IDENT")return null;let r=(o.text??o.value??"").toLowerCase();return r!=="up"&&r!=="down"||t[e+1]?.type!=="NUMBER"||t[e+2]?.type!=="PERCENT"?null:chunkZSLVLMO5_cjs.b(r==="up"?"PCT_UP":"PCT_DOWN",r,[o])}function Ha(t=68){return {name:"percentage:up-down",priority:t,shape:[{types:["NUMBER","RPAREN","IDENT"]}],match(e,o){let r=e[o];if(r&&(r.type==="NUMBER"||r.type==="RPAREN")){let i=Fa(e,o+1);if(i)return {consumed:2,replacement:[r,i],ruleName:"percentage:up-down"}}let n=Fa(e,o);return n?{consumed:1,replacement:[n],ruleName:"percentage:up-down"}:null}}}var nn={name:"solve-percentage",phrases:{"of what is":"OF_WHAT_IS","of what":"OF_WHAT","off what":"OFF_WHAT","on what":"ON_WHAT","on what is":"ON_WHAT_IS","off what is":"OFF_WHAT_IS"},infixParselets:{PERCENT:new wt,IS:new kt,PCT_ON:new qe(1),PCT_OFF:new qe(-1),OF:new Bt,OF_WHAT_IS:new Mt,ON_WHAT_IS:new Ze(1),OFF_WHAT_IS:new Ze(-1),TO:new Ut,INCREASE_BY:new et(1),DECREASE_BY:new et(-1),PCT_UP:new tt(1),PCT_DOWN:new tt(-1)},prefixParselets:{INCREASE:new Je(1),DECREASE:new Je(-1)},normalizerRules:[Va(),Ha()]};var an={sqrt:0,abs:1,sin:2,cos:3,tan:4,log:5,ceil:6,floor:7,round:8,min:9,max:10,asin:11,acos:12,atan:13,atan2:14,arcsin:11,arccos:12,arctan:13,sind:87,cosd:88,tand:89,asind:90,acosd:91,atand:92,sinh:15,cosh:16,tanh:17,asinh:18,acosh:19,atanh:20,cbrt:21,clz32:22,expm1:23,exp:24,fround:25,hypot:26,imul:27,log10:28,log1p:29,log2:30,pow:31,random:32,sign:33,trunc:34,degtorad:35,radtodeg:36,gcd:38,lcm:39,permutation:40,combination:41,hex:48,bin:49,int:50,compoundinterest:51,interestearned:52,compoundinterestrate:53,compoundinterestyears:54,loanrepayment:55,loaninterest:56,monthlypayment:57,taxadd:58,taxremove:59,inflationadjust:60,root:61,fact:62,factorial:62,transpose:63,det:64,inv:65,dot:66},Dt=class{constructor(){this.category="Function";}parse(e,o,r){let n=o.value.toLowerCase(),i=an[n];if(i===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown function: ${n}`,{functionName:n});e.consume("LPAREN");let a=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),a++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),a++;e.consume("RPAREN"),r.emitOpcode(51),r.emitIndex(i),r.emitIndex(a);}};var sn={name:"solve-function",prefixParselets:{FUNC:new Dt}};var de=class{constructor(e=0){this.category="Date/Time";this.dayOffset=e;}parse(e,o,r){r.emitOpcode(90),this.dayOffset!==0&&(r.emitOpcode(10),r.emitNumber(this.dayOffset),r.emitOpcode(13),r.emitString("days"),r.emitOpcode(80),r.emitOpcode(20));}};var ic={SUNDAY:0,MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6},rt=class{constructor(e){this.direction=e;this.category="Date/Time";}parse(e,o,r){let n=e.peek(),i=n?ic[n.type]:void 0;if(i===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("MISSING_WEEKDAY",`"${o.value}" must be followed by a day of the week (e.g. "${o.value} Saturday")`,{keyword:o.value,actualType:n?.type,actualValue:n?.value});e.consume(),r.emitOpcode(90),r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(this.direction==="next"?93:94);}};var ot=class{constructor(e){this.direction=e;this.category="Date/Time";}parse(e,o,r){let n=o.value;this.direction==="until"?(e.parseExpression(0,r),r.emitOpcode(90)):(r.emitOpcode(90),e.parseExpression(0,r)),r.emitOpcode(21),r.emitOpcode(13),r.emitString(n),r.emitOpcode(84);}};var bt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(0,r),r.emitPluginCall("workdaysInDuration",1);}};var nt=class{constructor(e){this.direction=e;this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Sum,n),n.emitOpcode(96),n.emitByte(this.direction==="backward"?1:0);}};var Vt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(97);}};var ee=class{constructor(e,o){this.functionName=e;this.mode=o;this.category="Date/Time";}parse(e,o,r){this.mode==="in"?(r.emitOpcode(90),e.parseExpression(0,r),r.emitOpcode(20)):e.peek()?e.parseExpression(0,r):r.emitOpcode(90),r.emitPluginCall(this.functionName,1);}};var Ft=class{constructor(){this.category="Date/Time";}parse(e,o,r){let n=o.value;e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("spanBetweenDates",2),r.emitOpcode(13),r.emitString(n),r.emitOpcode(84);}};var it=class{constructor(e){this.functionName=e;this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall(this.functionName,1);}};var Ht=class{constructor(){this.category="Date/Time";}parse(e,o,r){r.emitOpcode(90),r.emitPluginCall("toTimestampFromAny",1);}};var Gt=class{constructor(){this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("toDateFromAny",1);}};var zt=class{constructor(){this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("toTimestampFromAny",1);}};var ac="datetimeLiteralGrain",Kt=class{constructor(){this.category="Date/Time";}parse(e,o,r){r.emitOpcode(95),r.emitNumber(Number(o.value));let{grain:n,zone:i}=chunk7RC6RBS6_cjs.d(o.text);n!=="date"&&(r.emitOpcode(13),r.emitString(n),r.emitOpcode(13),r.emitString(i??""),r.emitPluginCall(ac,3));}};var $t=class{constructor(){this.category="Date/Time";}parse(e,o,r){let n=o.fault??{code:"DATE_NOT_A_CALENDAR_DAY",message:`"${o.value}" is not a date this engine can read.`};r.emitOpcode(13),r.emitString(n.code),r.emitOpcode(13),r.emitString(n.message),r.emitPluginCall("dateLiteralFault",2);}};var Wt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.consume("OF"),e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r),r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("nthWeekdayOfMonth",2);}};var Se=class{constructor(e){this.offsetMonths=e;this.category="Date/Time";}parse(e,o,r){r.emitOpcode(90),r.emitOpcode(10),r.emitNumber(this.offsetMonths),r.emitPluginCall("monthAnchorShift",2);}};var sc=new Set(["year","years","month","months","day","days"]),Yt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r),this.wordIs(e.peek(),"on")?(e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r)):r.emitOpcode(90);let n=this.consumeBreakdown(e)?"ymd":"years";r.emitOpcode(13),r.emitString(n),r.emitPluginCall("ageBetween",3);}wordIs(e,o){return e?String(e.value??e.text??"").toLowerCase()===o:false}consumeBreakdown(e){if(e.peek()?.type!=="IN")return false;e.consume();let o=false;for(;;){let r=e.peek();if(!r)break;let n=String(r.value??r.text??"").toLowerCase();if(r.type==="UNIT"&&sc.has(n))o=true,e.consume();else if(r.type==="COMMA"||r.type==="AND_CONJ"||n==="and")e.consume();else break}return o}};function mc(t){let e=t[0],o;if(e.type===6&&e.unit){if(chunkZKFCKAIX_cjs.c(e.unit)!=="time")return chunkGJZIJK2Q_cjs.P("WORKDAYS_IN_EXPECTED_DURATION",`"workdays in" expects a time duration, got unit "${e.unit}"`);o=chunkZKFCKAIX_cjs.e(e.toNumber(),e.unit,"day");}else o=e.toNumber();let r=o<0?-1:1,n=Math.abs(o),i=Math.floor(n/7),a=n-i*7,s=r*(i*5+Math.min(a,5));return chunkGJZIJK2Q_cjs.n(s)}var lc=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function at(t,e){return t.type===4?t.toNumber():chunkGJZIJK2Q_cjs.P("DATE_FIELD_EXPECTED_DATE",`"${e}" expects a date, got ${chunkGJZIJK2Q_cjs.g[t.type]??"an unsupported value"}`)}function uc(t,e){let o=at(t[0],"weekday");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.t(lc[chunkTPPM4QSS_cjs.c(e).fields(o).weekday])}var cc=["January","February","March","April","May","June","July","August","September","October","November","December"];function pc(t,e){let o=at(t[0],"month");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.t(cc[chunkTPPM4QSS_cjs.c(e).fields(o).month0])}function fc(t,e){let o=at(t[0],"week");if(typeof o!="number")return o;let r=chunkTPPM4QSS_cjs.c(e).fields(o);return chunkGJZIJK2Q_cjs.n(chunkE4HAKNBQ_cjs.e(r.year,r.month0,r.day))}function Ga(t,e){let o=e.fields(t).weekday;return o===0||o===6}function dc(t,e){let o=at(t[0],"is a weekend");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.L(Ga(o,chunkTPPM4QSS_cjs.c(e)))}function Ec(t,e){let o=at(t[0],"is a workday");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.L(!Ga(o,chunkTPPM4QSS_cjs.c(e)))}var Tc=864e5;function Nc(t,e){let o=t[0].toNumber(),r=t[1].toNumber(),n=chunkTPPM4QSS_cjs.c(e),i=n.fields(o),a=n.fields(r);if(n.localMidnight(i.year,i.month0,i.day)===o&&n.localMidnight(a.year,a.month0,a.day)===r){let l=Math.abs(chunkE4HAKNBQ_cjs.c(a.year,a.month0,a.day)-chunkE4HAKNBQ_cjs.c(i.year,i.month0,i.day));return chunkGJZIJK2Q_cjs.u(l*Tc,"ms")}return chunkGJZIJK2Q_cjs.u(Math.abs(o-r),"ms")}function yc(t,e){let o=t[0];if(o.type===4)return o;if(o.type===3){let r=chunk7RC6RBS6_cjs.c(o.value,chunkTPPM4QSS_cjs.c(e));return r===null?chunkGJZIJK2Q_cjs.P("INVALID_ISO8601_STRING",`"${o.value}" is not a recognizable ISO8601 date/time string`):chunkGJZIJK2Q_cjs.M(r)}return chunkGJZIJK2Q_cjs.M(chunk7RC6RBS6_cjs.f(o.toNumber()))}function gc(t){let e=t[0],o=t[1].value,r=t[2].value;return chunkGJZIJK2Q_cjs.M(e.toNumber(),o,r===""?void 0:r)}function Pc(t,e){let o=t[0];if(o.type===3){let r=chunk7RC6RBS6_cjs.c(o.value,chunkTPPM4QSS_cjs.c(e));return r===null?chunkGJZIJK2Q_cjs.P("INVALID_ISO8601_STRING",`"${o.value}" is not a recognizable ISO8601 date/time string`):chunkGJZIJK2Q_cjs.n(Math.floor(r/1e3))}return chunkGJZIJK2Q_cjs.n(Math.floor(o.toNumber()/1e3))}var za=mc,mn=uc,ln=pc,un=fc,Ka=dc,$a=Ec,Wa=Nc,Ya=yc,ja=Pc,Xa=gc;function qa(t,e,o,r,n){let i=n.fields(n.localMidnight(t,e,1)).weekday,s=1+(o-i+7)%7+(r-1)*7;return s<1||s>chunkE4HAKNBQ_cjs.b(t,e)?null:n.localMidnight(t,e,s)}function Za(t,e,o,r){let n=chunkE4HAKNBQ_cjs.b(t,e),a=(r.fields(r.localMidnight(t,e,n)).weekday-o+7)%7;return r.localMidnight(t,e,n-a)}function Ja(t,e,o){let r=o.fields(t),n=o.fields(e),i=n.year-r.year;return (n.month0<r.month0||n.month0===r.month0&&n.day<r.day)&&i--,i}function Qa(t,e){let o=t.year,r=t.month0+e,n=o+Math.floor(r/12),i=(r%12+12)%12,a=Math.min(t.day,chunkE4HAKNBQ_cjs.b(n,i));return {year:n,month0:i,day:a}}function es(t,e,o){let r=o.fields(t),n=o.fields(e),i=(n.year-r.year)*12+(n.month0-r.month0),a=Qa(r,i);o.localMidnight(a.year,a.month0,a.day)>e&&(i--,a=Qa(r,i));let s=chunkE4HAKNBQ_cjs.c(n.year,n.month0,n.day)-chunkE4HAKNBQ_cjs.c(a.year,a.month0,a.day);return {years:Math.floor(i/12),months:i%12,days:s}}function ts(t,e,o){let r=o.fields(t);return o.localMidnight(r.year,r.month0+e,1)}function Xt(t,e){return t.type===4?t.toNumber():chunkGJZIJK2Q_cjs.P("DATE_EXPECTED",`"${e}" expects a date, got ${chunkGJZIJK2Q_cjs.g[t.type]??"an unsupported value"}`)}function _c(t,e){let o=Xt(t[0],"nth weekday of month");if(typeof o!="number")return o;let r=String(t[1].value??""),[n,i]=r.split(":"),a=Number(i),s=chunkTPPM4QSS_cjs.c(e),l=s.fields(o),u=l.year,c=l.month0;if(n==="last")return chunkGJZIJK2Q_cjs.M(Za(u,c,a,s));let f=Number(n),T=qa(u,c,a,f,s);return T===null?chunkGJZIJK2Q_cjs.P("NTH_WEEKDAY_OUT_OF_RANGE",`there is no ${n}${xc(f)} occurrence of that weekday in the month`):chunkGJZIJK2Q_cjs.M(T)}function xc(t){let e=t%100;if(e>=11&&e<=13)return "th";switch(t%10){case 1:return "st";case 2:return "nd";case 3:return "rd";default:return "th"}}function Ac(t,e){let o=Xt(t[0],"month anchor");if(typeof o!="number")return o;let r=t[1].toNumber();return chunkGJZIJK2Q_cjs.M(ts(o,r,chunkTPPM4QSS_cjs.c(e)))}var Rc="ymd";function Oc(t,e){let o=Xt(t[0],"age of");if(typeof o!="number")return o;let r=Xt(t[1],"age of");if(typeof r!="number")return r;let n=String(t[2].value??"years"),i=chunkTPPM4QSS_cjs.c(e);return n===Rc?chunkGJZIJK2Q_cjs.t(Cc(es(o,r,i))):chunkGJZIJK2Q_cjs.u(Ja(o,r,i),"years")}function Cc(t){let e=[];return t.years!==0&&e.push(jt(t.years,"year")),t.months!==0&&e.push(jt(t.months,"month")),t.days!==0&&e.push(jt(t.days,"day")),e.length===0?jt(0,"day"):e.join(", ")}function jt(t,e){return `${t} ${e}${Math.abs(t)===1?"":"s"}`}var rs=_c,os=Ac,ns=Oc;function Ic(t){return chunkGJZIJK2Q_cjs.P(String(t[0].value??"DATE_NOT_A_CALENDAR_DAY"),String(t[1].value??""))}var is=Ic;var hc={SUNDAY:0,MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6},as="NTH_WEEKDAY",Sc=chunkYBQOQTVL_cjs.c(as),Lc=/^(\d+)(st|nd|rd|th)$/i;function ss(t=66){let e="datetime:nth-weekday";return {name:e,priority:t,unshapedReason:"Reads an ordinal that may be the LAST keyword, a number, or a word like `third`, so no fixed first-token set describes it.",match(o,r){let n=o[r];if(!n)return null;let i=null,a=0;if(n.type==="LAST")i="last",a=1;else {let f=o[r+1];if(!f||(n.sourceEnd??n.offset+(n.text?.length??0))!==f.offset)return null;let N=(n.text??"")+(f.text??""),E=Lc.exec(N);if(!E)return null;i=String(Number(E[1])),a=2;}let s=o[r+a],l=s?hc[s.type]:void 0;if(l===void 0||o[r+a+1]?.type!=="OF")return null;let u=`${i}:${l}`,c=new chunk6EYKVQT3_cjs.a(as,Sc,u,u,n.offset,0,n.line,n.col);return {consumed:a+1,replacement:[c],ruleName:e}}}}function ms(t=60){return {name:"datetime:until-since",priority:t,shape:[{types:["UNIT"]},{types:["UNTIL","SINCE"]}],match(e,o){if(o+1>=e.length)return null;let r=e[o],n=e[o+1];if(r.type!=="UNIT"||n.type!=="UNTIL"&&n.type!=="SINCE")return null;let i=n.type==="UNTIL"?"UNTIL_UNIT":"SINCE_UNIT";return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b(i,r.value,[r,n])],ruleName:`datetime:${n.type.toLowerCase()}`}}}}function ls(t=60){return {name:"datetime:between-unit",priority:t,startTokenTypes:["UNIT","IDENT"],match(e,o){let r=o,n=0;e[o]?.value?.toLowerCase()==="how"&&e[o+1]?.value?.toLowerCase()==="many"&&(r=o+2,n=2);let i=e[r],a=e[r+1];if(!i||!a||i.type!=="UNIT")return null;let s=a.type==="BETWEEN",l=a.type==="UNTIL"||a.type==="SINCE";if(!s&&!l||l&&n===0)return null;let u=e.slice(o,r+2);return l?{consumed:n+2,replacement:[i,a],ruleName:"datetime:how-many"}:{consumed:n+2,replacement:[chunkZSLVLMO5_cjs.b("BETWEEN_UNIT",i.value,u)],ruleName:"datetime:between"}}}}function us(t=70){return {name:"datetime:workday-rate-denominator",priority:t,shape:[{types:["SLASH"]},{types:["UNIT"],values:["workday","workdays"]}],match(e,o){let r=e[o];if(r.type!=="SLASH")return null;let n=e[o+1];if(!n||n.type!=="UNIT"||n.value!=="workday"&&n.value!=="workdays")return null;let i={...n,type:"NUMBER",typeId:chunkYBQOQTVL_cjs.c("NUMBER"),value:"1",text:"1"};return {consumed:2,replacement:[r,i,n],ruleName:"datetime:workday-rate-denominator"}}}}var vc=93,wc={q1:[0,2],q2:[3,5],q3:[6,8],q4:[9,11]};function kc(t){return chunkE4HAKNBQ_cjs.b(t,1)===29?366:365}function Bc(t){return t.fields(t.now()).year}var Qt=class{constructor(){this.category="Datetime";}parse(e,o,r){let n=this.readPeriodDays(e);r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(51),r.emitIndex(vc),r.emitIndex(1);}readPeriodDays(e){let o=e.getCalendar(),r=e.peek(),n=(r?.text??r?.value??"").toLowerCase(),i=wc[n];if(i!==void 0){e.consume();let s=this.readOptionalYear(e)??Bc(o),l=0;for(let u=i[0];u<=i[1];u++)l+=chunkE4HAKNBQ_cjs.b(s,u);return l}if(r?.type==="DATETIME_LITERAL"){e.consume();let s=o.fields(Number(r.value));return chunkE4HAKNBQ_cjs.b(s.year,s.month0)}let a=this.readOptionalYear(e);if(a!==null)return kc(a);throw chunkGXO7TSXQ_cjs.c.parsing("DAYS_IN_EXPECTED_PERIOD",'Expected a month, quarter or year, as in "days in February 2020" or "days in Q3"')}readOptionalYear(e){let o=e.peek();if(o?.type!=="NUMBER")return null;let r=o.text??o.value??"";return /^\d{4}$/.test(r)?(e.consume(),Number(r)):null}};var Mc=new Set(["q1","q2","q3","q4"]),Uc=new Set(["january","jan","february","feb","march","mar","april","apr","may","june","jun","july","jul","august","aug","september","sep","sept","october","oct","november","nov","december","dec"]);function Dc(t){if(t===void 0)return false;if(t.type==="DATETIME_LITERAL")return true;let e=(t.text??t.value??"").toLowerCase();return t.type==="IDENT"||t.type==="UNIT"?Mc.has(e)||Uc.has(e):t.type==="NUMBER"&&/^\d{4}$/.test(t.text??"")}function cs(t=60){return {name:"datetime:days-in-period",priority:t,shape:[{types:["UNIT","IDENT"],values:["days"]},{types:["IN"]}],match(e,o){let r=e[o];return r===void 0||(r.text??r.value??"").toLowerCase()!=="days"||r.type!=="UNIT"&&r.type!=="IDENT"||e[o+1]?.type!=="IN"||!Dc(e[o+2])?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("DAYS_IN_PERIOD","days in",[r,e[o+1]])],ruleName:"datetime:days-in-period"}}}}function ps(){return {name:"datetime:daily-note-link",priority:80,shape:[{types:["LBRACKET"]},{types:["LBRACKET"]}],match(t,e){return t[e]?.type!=="LBRACKET"||t[e+1]?.type!=="LBRACKET"||t[e+2]?.type!==chunk7RC6RBS6_cjs.o||t[e+3]?.type!=="RBRACKET"||t[e+4]?.type!=="RBRACKET"?null:{consumed:5,replacement:[t[e+2]],ruleName:"datetime:daily-note-link"}}}}var cn={name:"solve-datetime",phrases:{"workdays in":"WORKDAYS_IN","working days after":"WORKDAYS_AFTER","business days after":"WORKDAYS_AFTER","working day after":"WORKDAYS_AFTER","business day after":"WORKDAYS_AFTER","working days from":"WORKDAYS_AFTER","business days from":"WORKDAYS_AFTER","working day from":"WORKDAYS_AFTER","business day from":"WORKDAYS_AFTER","working days before":"WORKDAYS_BEFORE","business days before":"WORKDAYS_BEFORE","working day before":"WORKDAYS_BEFORE","business day before":"WORKDAYS_BEFORE","working days between":"WORKDAYS_BETWEEN","business days between":"WORKDAYS_BETWEEN","day of the week on":"WEEKDAY_ON","weekday on":"WEEKDAY_ON","current timestamp":"CURRENT_TIMESTAMP","to date":"TO_DATE","to timestamp":"TO_TIMESTAMP","what day is it":"WEEKDAY_ON","what day is it on":"WEEKDAY_ON","what day will it be on":"WEEKDAY_ON","what day is it in":"WEEKDAY_IN","what day will it be in":"WEEKDAY_IN","what month is it":"MONTH_ON","what month is it on":"MONTH_ON","month of":"MONTH_ON","what month is it in":"MONTH_IN","what month will it be in":"MONTH_IN","what week is it":"WEEK_ON","what week is it on":"WEEK_ON","week of":"WEEK_ON","week number on":"WEEK_ON","week number of":"WEEK_ON","week number":"WEEK_ON","what week is it in":"WEEK_IN","what week will it be in":"WEEK_IN","is a weekend":"IS_WEEKEND","is on a weekend":"IS_WEEKEND","is a workday":"IS_WORKDAY","is a weekday":"IS_WORKDAY","is a business day":"IS_WORKDAY","age of":"AGE_OF","next month":"MONTH_ANCHOR_NEXT","this month":"MONTH_ANCHOR_THIS","last month":"MONTH_ANCHOR_LAST"},prefixParselets:{DAYS_IN_PERIOD:new Qt,NOW:new de(0),TODAY:new de(0),TOMORROW:new de(1),YESTERDAY:new de(-1),NEXT:new rt("next"),LAST:new rt("last"),UNTIL_UNIT:new ot("until"),SINCE_UNIT:new ot("since"),WORKDAYS_IN:new bt,WORKDAYS_BETWEEN:new Vt,WEEKDAY_ON:new ee("weekdayOnDate","on"),WEEKDAY_IN:new ee("weekdayOnDate","in"),MONTH_ON:new ee("monthOnDate","on"),MONTH_IN:new ee("monthOnDate","in"),WEEK_ON:new ee("weekOnDate","on"),WEEK_IN:new ee("weekOnDate","in"),BETWEEN_UNIT:new Ft,CURRENT_TIMESTAMP:new Ht,DATETIME_LITERAL:new Kt,DATETIME_LITERAL_UNREADABLE:new $t,NTH_WEEKDAY:new Wt,AGE_OF:new Yt,MONTH_ANCHOR_NEXT:new Se(1),MONTH_ANCHOR_THIS:new Se(0),MONTH_ANCHOR_LAST:new Se(-1)},infixParselets:{WORKDAYS_AFTER:new nt("forward"),WORKDAYS_BEFORE:new nt("backward"),TO_DATE:new Gt,TO_TIMESTAMP:new zt,IS_WEEKEND:new it("isWeekendOnDate"),IS_WORKDAY:new it("isWorkdayOnDate")},normalizerRules:[ms(),ls(),us(),ss(),cs(),ps()],pluginFunctions:{workdaysInDuration:za,weekdayOnDate:mn,toDateFromAny:Ya,toTimestampFromAny:ja,datetimeLiteralGrain:Xa,monthOnDate:ln,weekOnDate:un,isWeekendOnDate:Ka,isWorkdayOnDate:$a,spanBetweenDates:Wa,nthWeekdayOfMonth:rs,monthAnchorShift:os,ageBetween:ns,dateLiteralFault:is},asConverters:{iso8601:(t,e)=>chunkGJZIJK2Q_cjs.t(chunk7RC6RBS6_cjs.e(t.toNumber(),chunkTPPM4QSS_cjs.c(e))),weekday:(t,e)=>mn([t],e),month:(t,e)=>ln([t],e),week:(t,e)=>un([t],e)},tokenCategories:{NTH_WEEKDAY:"datetime",MONTH_ANCHOR_NEXT:"datetime",MONTH_ANCHOR_THIS:"datetime",MONTH_ANCHOR_LAST:"datetime",AGE_OF:"keyword",DATETIME_LITERAL_UNREADABLE:"datetime"}};function pn(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let r=chunkE4HAKNBQ_cjs.h(e)*6e4;return o.formatTimeInZone("UTC",t+r)}return o.formatTimeInZone(e,t)}function ds(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let r=chunkE4HAKNBQ_cjs.h(e)*6e4;return o.formatDateInZone("UTC",t+r)}return o.formatDateInZone(e,t)}function fs(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let n=chunkE4HAKNBQ_cjs.d(t+chunkE4HAKNBQ_cjs.h(e)*6e4);return {year:n.year,month0:n.month0,day:n.day}}let r=o.fieldsInZone(e,t);return {year:r.year,month0:r.month0,day:r.day}}function Es(t,e,o,r){let n=fs(t,e,r),i=fs(t,o,r),a=chunkE4HAKNBQ_cjs.a(n.year,n.month0,n.day),s=chunkE4HAKNBQ_cjs.a(i.year,i.month0,i.day);return Math.round((a-s)/864e5)}function fn(t){if(chunkE4HAKNBQ_cjs.g(t)){let o=chunkE4HAKNBQ_cjs.h(t),r=o>=0?"+":"-",n=Math.abs(o),i=Math.floor(n/60),a=n%60;return a===0?`UTC${r}${i}`:`UTC${r}${i}:${String(a).padStart(2,"0")}`}return (t.split("/").pop()??t).replace(/_/g," ")}function me(t){let e=t.peek();if(!e)return null;let o=e.value,r=o.toLowerCase();if(r==="gmt"||r==="utc"){t.consume();let i=t.peek();if(i?.type==="PLUS"||i?.type==="MINUS"){let s=i.type==="MINUS";t.consume();let l=t.peek(),u;if(l?.type==="CLOCK_TIME")t.consume(),u=parseInt(l.value,10);else {let f=t.consume("NUMBER");if(u=parseInt(f.value,10)*60,t.peek()?.type==="COLON"){t.consume();let T=t.consume("NUMBER");u+=parseInt(T.value,10);}}let c=chunkE4HAKNBQ_cjs.f(s?-u:u);return {zoneRef:c,displayName:fn(c)}}let a=chunkE4HAKNBQ_cjs.f(0);return {zoneRef:a,displayName:fn(a)}}let n=chunkQQHHZPEW_cjs.M[r];if(n){t.consume();let i=o.replace(/\b\w/g,a=>a.toUpperCase());return {zoneRef:n,displayName:i}}return null}var qt="zoneConvert",dn="timeInZone",En="dateInZone",Zt="timeDifference";function Ts(t,e){let o=t[0].toNumber(),r=t[1].value,n=t[2].value,i=chunkTPPM4QSS_cjs.c(e),a=i.fields(i.now()),s=chunkE4HAKNBQ_cjs.j(a.year,a.month0,a.day,Math.floor(o/60),o%60,r,i),l=pn(s,n,i),u=Es(s,n,r,i);if(u===0)return chunkGJZIJK2Q_cjs.t(l);let c=u>0?"+":"";return chunkGJZIJK2Q_cjs.t(`${l} (${c}${u} day${Math.abs(u)===1?"":"s"})`)}function Ns(t,e){let o=t[0].value,r=chunkTPPM4QSS_cjs.c(e);return chunkGJZIJK2Q_cjs.t(pn(r.now(),o,r))}function ys(t,e){let o=t[0].value,r=chunkTPPM4QSS_cjs.c(e);return chunkGJZIJK2Q_cjs.t(ds(r.now(),o,r))}function gs(t,e){let o=t[0].value,r=t[1].value,n=t[2].value,i=t[3].value,a=chunkTPPM4QSS_cjs.c(e),s=a.now(),l=chunkE4HAKNBQ_cjs.i(o,s,a),c=chunkE4HAKNBQ_cjs.i(r,s,a)-l;if(c===0)return chunkGJZIJK2Q_cjs.t(`${i} and ${n} currently share the same UTC offset`);let f=c>0?i:n,T=c>0?n:i,N=Math.abs(c),E=Math.floor(N/60),P=N%60,R=[];return E>0&&R.push(`${E} hour${E===1?"":"s"}`),P>0&&R.push(`${P} minute${P===1?"":"s"}`),chunkGJZIJK2Q_cjs.t(`${f} is ${R.join(" ")} ahead of ${T}`)}var Jt=class{constructor(){this.category="Time";}parse(e,o,r){let n=parseInt(o.value,10),i=me(e);if(i!==null){if(e.peek()?.type!=="IN")throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_IN",`Expected "in <city>" after the zone name (e.g. "6pm Sydney in Chicago") but got ${e.peek()?`"${e.peek().value}"`:"end of input"}`);e.consume();let a=me(e);if(a===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_TARGET",'Expected a city or zone name after "in" (e.g. "6pm Sydney in Chicago")');r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(13),r.emitString(i.zoneRef),r.emitOpcode(13),r.emitString(a.zoneRef),r.emitPluginCall(qt,3);return}r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(120);}};var er=class{constructor(){this.category="Time";}parse(e,o,r){let[n,i]=o.value.split(":"),a=parseInt(n,10),s=parseInt(i,10),l=s>=a?s-a:1440-a+s;r.emitOpcode(10),r.emitNumber(l),r.emitOpcode(13),r.emitString("minutes"),r.emitOpcode(80);}};var tr=class{constructor(){this.category="Time";}parse(e,o,r){r.emitOpcode(10),r.emitNumber(parseFloat(o.value)),r.emitOpcode(13),r.emitString("frames/s"),r.emitOpcode(80);}};var rr=class{constructor(){this.category="Time";}parse(e,o,r){r.emitOpcode(10),r.emitNumber(parseFloat(o.value)),r.emitOpcode(13),r.emitString("s"),r.emitOpcode(80);}};function Tn(t){return {category:"Time",parse(e,o,r){let n=me(e);if(n===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_CITY",`Expected a city or zone name after "${o.value}" (e.g. "time in Paris")`);r.emitOpcode(13),r.emitString(n.zoneRef),r.emitPluginCall(t,1);}}}var or=class{constructor(){this.category="Time";}parse(e,o,r){let n=me(e);if(n===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_DIFFERENCE_EXPECTED_CITY",'Expected a city or zone name after "time difference between" (e.g. "time difference between Seattle and Moscow")');e.consume("AND_CONJ");let i=me(e);if(i===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_DIFFERENCE_EXPECTED_SECOND_CITY",'Expected a second city or zone name after "and" (e.g. "time difference between Seattle and Moscow")');r.emitOpcode(13),r.emitString(n.zoneRef),r.emitOpcode(13),r.emitString(i.zoneRef),r.emitOpcode(13),r.emitString(n.displayName),r.emitOpcode(13),r.emitString(i.displayName),r.emitPluginCall(Zt,4);}};var nr=class{constructor(){this.category="Time";}parse(e,o,r){let[n,i,a,s]=o.value.split(",").map(Number),l=e.peek();if(!l||l.type!=="RATE_AT"&&l.type!=="AT")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`A video timecode must specify a frame rate, e.g. "${o.value.split(",").join(":")} at 30 fps" or "... @ 30 fps"`);e.consume();let u=e.peek();if(!u||u.type!=="FPS_RATE")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`Expected "<number> fps" after "${l.value}" (e.g. "at 30 fps")`);e.consume();let c=parseFloat(u.value),f=Math.round(c);if(s>=f)throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_FRAME_OUT_OF_RANGE",`Frame number ${s} is out of range for ${c} fps (must be 0-${f-1})`);let T=(n*3600+i*60+a)*f+s,N=chunkGJZIJK2Q_cjs.z(c);if(e.peek()?.type==="IN"){e.consume();let E=e.peek();if(!E||E.type!=="IDENT"||E.value.toLowerCase()!=="frames")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FRAMES",`Expected "frames" after "in" (e.g. "... in frames") but got ${E?`"${E.value}"`:"end of input"}`);e.consume(),N="frames";}r.emitOpcode(10),r.emitNumber(T),r.emitOpcode(13),r.emitString(N),r.emitOpcode(80);}};function Ps(t,e){let o=Math.max(1,Math.round(e)),r=c=>String(c).padStart(2,"0"),n=Math.trunc(t),i=(n%o+o)%o,a=Math.floor(n/o),s=Math.floor(a/3600),l=Math.floor(a%3600/60),u=a%60;return `${r(s)}:${r(l)}:${r(u)}:${r(i)}`}var ir=class{constructor(){this.category="Time";}parse(e,o,r){let n=parseFloat(o.value),i=e.peek();if(i&&(i.type==="RATE_AT"||i.type==="AT")){e.consume();let a=e.peek();if(!a||a.type!=="FPS_RATE")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`Expected "<number> fps" after "${i.value}" (e.g. "@ 30 fps")`);e.consume();let s=parseFloat(a.value);r.emitOpcode(13),r.emitString(Ps(n,s));return}r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(13),r.emitString("frames"),r.emitOpcode(80);}};function _s(t,e,o){if(e<0||e>59)return null;if(o){if(t<1||t>12)return null;let r=o.toLowerCase()==="pm";return (t%12+(r?12:0))*60+e}return t<0||t>23?null:t*60+e}function xs(t){return !!t&&t.type==="IDENT"&&/^(am|pm)$/i.test(t.value)}function As(t=65){return {name:"time:clock-time",priority:t,shape:[{types:["NUMBER"]},{types:["COLON","IDENT"]}],match(e,o){let r=e[o];if(r.type!=="NUMBER")return null;let n=parseInt(r.value,10);if(isNaN(n)||n<0||n>23||chunkZSLVLMO5_cjs.e(e,o))return null;let i=e[o+1],a=e[o+2];if(i?.type==="COLON"&&a?.type==="NUMBER"){let l=parseInt(a.value,10),u=e[o+3],c=xs(u),f=_s(n,l,c?u.value:void 0);if(f===null)return null;let T=c?4:3;return {consumed:T,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME",String(f),e.slice(o,o+T))],ruleName:"time:clock-time"}}let s=e[o+1];if(xs(s)){let l=_s(n,0,s.value);return l===null?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME",String(l),e.slice(o,o+2))],ruleName:"time:clock-time"}}return null}}}function Rs(t=66){return {name:"time:clock-time-interval",priority:t,shape:[{types:["CLOCK_TIME"]},{types:["TO"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];return r.type!=="CLOCK_TIME"||n?.type!=="TO"||i?.type!=="CLOCK_TIME"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME_INTERVAL",`${r.value}:${i.value}`,e.slice(o,o+3))],ruleName:"time:clock-time-interval"}}}}function Os(t=65){return {name:"time:fps-rate",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["fps"]}],match(e,o){let r=e[o],n=e[o+1];return r.type!=="NUMBER"||n?.type!=="IDENT"||n.value.toLowerCase()!=="fps"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("FPS_RATE",r.value,e.slice(o,o+2))],ruleName:"time:fps-rate"}}}}function Cs(t=70){return {name:"time:laptime",priority:t,shape:[{types:["NUMBER"]},{types:["COLON"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2],a=e[o+3],s=e[o+4];if(r.type!=="NUMBER"||n?.type!=="COLON"||i?.type!=="NUMBER"||a?.type!=="COLON"||s?.type!=="NUMBER"||chunkZSLVLMO5_cjs.e(e,o))return null;let l=parseInt(r.value,10),u=parseInt(i.value,10),c=parseFloat(s.value);if(isNaN(l)||isNaN(u)||isNaN(c)||u<0||u>59||c<0||c>=60)return null;let f=l*3600+u*60+c;return {consumed:5,replacement:[chunkZSLVLMO5_cjs.b("LAPTIME",String(f),e.slice(o,o+5))],ruleName:"time:laptime"}}}}function Is(t=75){return {name:"time:video-timecode",priority:t,shape:[{types:["NUMBER"]},{types:["COLON"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2],a=e[o+3],s=e[o+4],l=e[o+5],u=e[o+6];if(r?.type!=="NUMBER"||n?.type!=="COLON"||i?.type!=="NUMBER"||a?.type!=="COLON"||s?.type!=="NUMBER"||l?.type!=="COLON"||u?.type!=="NUMBER"||chunkZSLVLMO5_cjs.e(e,o))return null;let c=parseInt(r.value,10),f=parseInt(i.value,10),T=parseInt(s.value,10),N=parseInt(u.value,10);return [c,f,T,N].some(E=>isNaN(E))||f<0||f>59||T<0||T>59||c<0||N<0?null:{consumed:7,replacement:[chunkZSLVLMO5_cjs.b("VIDEO_TIMECODE",`${c},${f},${T},${N}`,e.slice(o,o+7))],ruleName:"time:video-timecode"}}}}function hs(t=65){return {name:"time:frame-count",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["frames"]}],match(e,o){let r=e[o],n=e[o+1];return r.type!=="NUMBER"||n?.type!=="IDENT"||n.value.toLowerCase()!=="frames"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("FRAME_COUNT",r.value,e.slice(o,o+2))],ruleName:"time:frame-count"}}}}var bc=14,Vc=[["week","weeks",604800],["day","days",86400],["hour","hours",3600],["minute","minutes",60],["second","seconds",1]];function Ss(t){if(t.type===0)return t.toNumber();if(t.type!==6||t.unit===void 0)return null;let e=chunkEZKR44MA_cjs.a[t.unit.toLowerCase()];return e===void 0||e[0]!==bc?null:t.toNumber()*e[1]}function Ls(t){let e=Ss(t);if(e===null)return chunkGJZIJK2Q_cjs.t(`"as timespan" needs a duration, got ${t.unit??"a non-duration"}`);let o=e<0,r=Math.abs(e),n=[];for(let[a,s,l]of Vc){if(l===1)break;let u=Math.floor(r/l);u>0&&(n.push(`${u} ${u===1?a:s}`),r-=u*l);}let i=Math.round(r*1e3)/1e3;return (i>0||n.length===0)&&n.push(`${i} ${i===1?"second":"seconds"}`),chunkGJZIJK2Q_cjs.t((o?"-":"")+n.join(" "))}function yn(t){let e=Ss(t);if(e===null)return chunkGJZIJK2Q_cjs.t(`"as laptime" needs a duration, got ${t.unit??"a non-duration"}`);let o=e<0,r=Math.round(Math.abs(e)*1e3)/1e3,n=Math.floor(r/3600),i=Math.floor(r%3600/60),a=r%60,s=Math.floor(a),l=Math.round((a-s)*1e3),u=`${Nn(n)}:${Nn(i)}:${Nn(s)}`;return chunkGJZIJK2Q_cjs.t((o?"-":"")+(l>0?`${u}.${String(l).padStart(3,"0")}`:u))}function Nn(t){return t<10?`0${t}`:String(t)}var gn={name:"solve-time",asConverters:{timespan:Ls,laptime:yn,lap:yn},phrases:{"time in":"TIME_IN","date in":"DATE_IN","time difference between":"TIME_DIFFERENCE_BETWEEN",...Object.fromEntries(Object.keys(chunkQQHHZPEW_cjs.L).map(t=>[t,"CITY_NAME"]))},prefixParselets:{CLOCK_TIME:new Jt,CLOCK_TIME_INTERVAL:new er,FPS_RATE:new tr,LAPTIME:new rr,TIME_IN:Tn(dn),DATE_IN:Tn(En),TIME_DIFFERENCE_BETWEEN:new or,VIDEO_TIMECODE:new nr,FRAME_COUNT:new ir},normalizerRules:[As(),Rs(),Os(),Cs(),Is(),hs()],pluginFunctions:{[qt]:Ts,[dn]:Ns,[En]:ys,[Zt]:gs}};function ar(t){for(let e of t.alternatives){let o=e.slots[0];if(!o||o.kind!=="keyword")throw chunkGXO7TSXQ_cjs.c.config("INVALID_PHRASE_PATTERN","Every PhraseAlternative's first slot must be a `keyword` slot \u2014 alternatives are chosen by peeking the next token, which only works if the choice is decidable from one leading keyword.",{category:t.category})}return {category:t.category,parse(e,o,r){let n=e.peek(),i=t.alternatives.find(s=>{let l=s.slots[0];return n!==void 0&&l.tokenTypes.includes(n.type)});if(!i){let s=t.alternatives.map(l=>l.slots[0].tokenTypes.join("|")).join(", ");throw chunkGXO7TSXQ_cjs.c.parsing("NO_MATCHING_PHRASE_ALTERNATIVE",`Expected one of [${s}] but got "${n?.type??"end of input"}" ("${n?.value??""}")`,{category:t.category,expected:s,actualType:n?.type,actualValue:n?.value})}let a=[];for(let s of i.slots)if(s.kind==="keyword"){let l=e.peek();if(!l||!s.tokenTypes.includes(l.type))throw chunkGXO7TSXQ_cjs.c.parsing("PHRASE_KEYWORD_MISMATCH",`Expected one of [${s.tokenTypes.join("|")}] but got "${l?.type??"end of input"}" ("${l?.value??""}")`,{category:t.category,expected:s.tokenTypes,actualType:l?.type,actualValue:l?.value});e.consume(),a.push({type:l.type,value:l.value});}else e.parseExpression(s.bindingPower??0,r);i.emit(r,a);}}}var Fc=37;function sr(t){t.emitOpcode(51),t.emitIndex(Fc),t.emitIndex(2);}var Hc=ar({category:"Dice",alternatives:[{slots:[{kind:"keyword",tokenTypes:["BETWEEN"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["AND_CONJ"]},{kind:"expr"}],emit:sr},{slots:[{kind:"keyword",tokenTypes:["FROM"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["TO"]},{kind:"expr"}],emit:sr},{slots:[{kind:"keyword",tokenTypes:["LPAREN"]},{kind:"expr"},{kind:"keyword",tokenTypes:["COMMA"]},{kind:"expr"},{kind:"keyword",tokenTypes:["RPAREN"]}],emit:sr}]}),mr=class{constructor(){this.category="Dice";}parse(e,o,r){let n=e.peek();if(n&&n.type==="NUMBER"){let i=e.consume();r.emitOpcode(10),r.emitNumber(parseFloat(i.value)),e.consume("MINUS");let a=e.consume();r.emitOpcode(10),r.emitNumber(parseFloat(a.value)),sr(r);return}Hc.parse(e,o,r);}};var Pn={name:"solve-dice",prefixParselets:{ROLL:new mr}};var lr=class{constructor(){this.category="Variable";}parse(e,o,r){let n=e.consume();if(n.type!=="IDENT"&&n.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("EXPECTED_IDENTIFIER",`Expected identifier or unit after colon, got ${n.type}`,{tokenType:n.type});let i=n.value;e.peek()?.type==="EQUALS"?(e.consume("EQUALS"),e.parseExpression(0,r),r.emitOpcode(61),r.emitString(i)):(r.emitOpcode(60),r.emitString(i));}};var st=class{constructor(){this.category="Variable";}parse(e,o,r){r.emitOpcode(60),r.emitString(o.value);}};var ur=class{constructor(){this.category="Variable";}parse(e,o,r){e.consume("COLON");let n=e.consume();if(n.type!=="IDENT"&&n.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("EXPECTED_IDENTIFIER",`Expected identifier after 'global :', got ${n.type}`,{tokenType:n.type});let i=n.value;e.peek()?.type==="EQUALS"?(e.consume("EQUALS"),e.parseExpression(0,r),r.emitOpcode(63),r.emitString(i)):(r.emitOpcode(62),r.emitString(i));}};var cr=class{constructor(){this.namespace="global-variables";this.local=true;this.pending=new Map;}preflight(e,o,r,n,i){let{opcodes:a,strings:s}=o,l=a.length,u=0;for(;u<l;){if(a[u]===62){let f=s[a[u+1]];if(!chunkQQHHZPEW_cjs.J.has(f))return this.pendingResultFor(f,r,n)}u=chunkG2V33LFM_cjs.a(a,u);}return null}pendingResultFor(e,o,r){let n=this.pending.get(e);return n||(n=new Promise(i=>{let a=chunkQQHHZPEW_cjs.J.subscribe((s,l)=>{s===e&&(a(),this.pending.delete(e),i(l));});}),this.pending.set(e,n)),{queryKey:`global:${e}`,resolver:n,packageId:o,signal:r,metadata:{varName:e}}}destroy(){this.pending.clear();}};var _n={name:"solve-variables",asyncResolvers:[new cr],prefixParselets:{COLON:new lr,IDENT:new st,UNIT:new st,GLOBAL:new ur}};var ws="currency-historical",Ee="historicalCurrency",Gc=`solve-currency:${Ee}`,pr={NOT_CONFIGURED:"HISTORICAL_RATES_NOT_CONFIGURED",QUERY_FAILED:"HISTORICAL_RATE_QUERY_FAILED",NOT_PREFLIGHTED:"HISTORICAL_RATE_NOT_PREFLIGHTED",INVALID_OPERAND:"HISTORICAL_CURRENCY_INVALID_OPERAND"},zc=3e4,ks=1/0,Kc=1e4;function xn(t,e,o){return [ws,`${t.toUpperCase()}:${e.toUpperCase()}:${o}`]}function vs(t){return t<10?`0${t}`:String(t)}function fr(t,e,o){if(!chunkTMQ37JQY_cjs.c.isCurrency(e)||o!==void 0&&!chunkTMQ37JQY_cjs.c.isCurrency(o))return null;let r=t.peek();if(!r||r.type!=="IDENT"||r.value.toLowerCase()!=="on")return null;let n=t.peekAt(1);if(!n||n.type!=="DATETIME_LITERAL")return null;t.consume(),t.consume();let i=t.getCalendar().fields(Number(n.value));return `${i.year}-${vs(i.month0+1)}-${vs(i.day)}`}async function Bs(t,e,o,r,n,i){let a=e.toUpperCase(),s=o.toUpperCase();if(!t)return chunkGJZIJK2Q_cjs.P(pr.NOT_CONFIGURED,`Historical exchange rates are not configured. Supply historicalRateProvider via createCurrencyPackage({ ... }) to convert ${a} to ${s} on ${r}.`);let{signal:l,cleanup:u}=chunkTLG7VZRX_cjs.a(n,Kc,"Historical currency rate fetch");try{let c=await t(a,s,r,l);return chunkGJZIJK2Q_cjs.n(c)}catch(c){let f=chunkGJZIJK2Q_cjs.P(pr.QUERY_FAILED,`Failed to resolve the historical rate for ${a} to ${s} on ${r}: ${c instanceof Error?c.message:String(c)}`),T=xn(e,o,r);return setTimeout(()=>{i.getQueryData(T)===f&&i.removeQueries({queryKey:T,exact:true});},zc).unref?.(),f}finally{u();}}function An(t){return e=>{let o=e[0],r=e[1],n=e[2],i=chunkGJZIJK2Q_cjs.Q(o);if(i)return i;if(o.type!==6||o.unit===void 0||!chunkTMQ37JQY_cjs.c.isCurrency(o.unit))return chunkGJZIJK2Q_cjs.P(pr.INVALID_OPERAND,'Historical conversion needs an amount in a currency, for example "100 USD in GBP on 2024-01-15".');let a=o.unit,s=String(r.value),l=String(n.value);if(a.toUpperCase()===s.toUpperCase())return chunkGJZIJK2Q_cjs.u(o.toNumber(),s);let u=chunkZLRJ7TDP_cjs.b(),c=xn(a,s,l),f=u?.getQueryData(c);if(f===void 0)return u?u.fetchQuery({queryKey:c,queryFn:({signal:N})=>Bs(t,a,s,l,N,u),staleTime:ks}):chunkGJZIJK2Q_cjs.P(pr.NOT_PREFLIGHTED,`No historical rate resolved for ${a.toUpperCase()} to ${s.toUpperCase()} on ${l}.`);if(f.type===13)return f;let T=f.value;return chunkGJZIJK2Q_cjs.u(o.toNumber()*T,s)}}function Ms(t){return {namespace:ws,preflight(e,o,r,n,i){let{opcodes:a,strings:s}=o,l=a.length,u=chunkQQHHZPEW_cjs.F(Gc),c=0,f=[];for(;c<l;){let T=a[c];if(T===13)f.push(a[c+1]);else if(T===50){let N=a[c+1],E=a[c+2];if(N===u&&E===3&&f.length>=3){let P=s[f[f.length-1]],R=s[f[f.length-2]],O=new Set;for(let g=0;g<f.length-2;g++){let _=s[f[g]];chunkTMQ37JQY_cjs.c.isCurrency(_)&&O.add(_.toUpperCase());}if(O.size===1){let g=O.values().next().value;if(g!==R.toUpperCase()){let _=xn(g,R,P);if(i.getQueryData(_)===void 0){let h=i.fetchQuery({queryKey:_,queryFn:({signal:S})=>Bs(t,g,R,P,S,i),staleTime:ks});return {queryKey:_.join(":"),resolver:h,packageId:r,signal:n,metadata:{from:g,to:R,isoDate:P}}}}}}f=[];}c=chunkG2V33LFM_cjs.a(a,c);}return null},destroy(){}}}function Us(t){return chunkFDKTESBC_cjs.ta(t)??t}var dr=class{constructor(){this.category="UoM";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){let i=Us(r.value);if(n.emitOpcode(13),n.emitString(i),!(e.infixMinBindingPower>=chunkZDJTDFTR_cjs.a.Product)&&(e.peek()?.type==="TO"||e.peek()?.type==="IN")){e.consume();let s=e.peek();if(s?.type==="UNIT"||s?.type==="IN"){e.consume();let l=Us(s.value),u=fr(e,l,i);if(u!==null){n.emitOpcode(80),n.emitOpcode(13),n.emitString(l),n.emitOpcode(13),n.emitString(u),n.emitPluginCall(Ee,3);return}n.emitOpcode(13),n.emitString(l),n.emitOpcode(81);return}if(s?.type==="QUESTION"){e.consume(),n.emitOpcode(85);return}}if(e.peek()?.type==="BEST"){e.consume(),n.emitOpcode(83);return}n.emitOpcode(80);}};function Rn(t){return chunkFDKTESBC_cjs.ta(t)??t}var Er=class{constructor(){this.category="UoM";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r);let n=e.peek();if(n&&n.type==="UNIT"){if(e.consume(),r.emitOpcode(13),r.emitString(Rn(n.value)),e.peek()?.type==="TO"){e.consume("TO");let i=e.consume();i?.type==="UNIT"?(r.emitOpcode(13),r.emitString(Rn(i.value)),r.emitOpcode(81)):i?.type==="BEST"&&r.emitOpcode(83);}else r.emitOpcode(80);return}if(n&&(n.type==="TO"||n.type==="IN")){e.consume();let i=e.peek();i?.type==="UNIT"||i?.type==="IN"||i?.type==="DOLLAR"||i?.type==="POUND"||i?.type==="EURO"||i?.type==="YEN"||i?.type==="RUBLE"||i?.type==="WON"||i?.type==="CURRENCY_SYMBOL"||i?.type==="IDENT"?(e.consume(),r.emitOpcode(13),r.emitString(Rn(i.value)),r.emitOpcode(84)):i?.type==="BEST"&&(e.consume(),r.emitOpcode(83));return}}};var Tr=class{constructor(){this.category="UoM";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitOpcode(85);}};function Ds(t=60){return {name:"uom:possibilities",priority:t,shape:[{types:["UNIT"]},{types:["TO"]}],match(e,o){if(o+2>=e.length)return null;let r=e[o],n=e[o+1],i=e[o+2];return r.type!=="UNIT"||n.type!=="TO"||i.type!=="QUESTION"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("UOM_POSSIBILITIES_QUERY",r.value,[r,n,i])],ruleName:"uom:possibilities"}}}}var bs=14;function Vs(t,e){if(t===void 0||t.type!=="UNIT")return;let o=(t.value??"").toLowerCase();if(o==="m"&&e===bs)return {kind:bs,ratio:60,spelling:"minutes"};let r=chunkEZKR44MA_cjs.a[o];return r===void 0?void 0:{kind:r[0],ratio:r[1],spelling:o}}var Fs=/^\d+(\.\d+)?$/;function Hs(t=63){return {name:"uom:compound-quantity",priority:t,shape:[{types:["NUMBER"]},{types:["UNIT"]}],match(e,o){let r=e[o];if(r?.type!=="NUMBER"||!Fs.test(r.text??""))return null;let n=Vs(e[o+1]);if(n===void 0)return null;let i=n.kind,a=n.ratio,s=Number(r.text)*a,l=n.spelling,u=e[o+1],c=2;for(;;){let N=e[o+c];if(N?.type!=="NUMBER"||!Fs.test(N.text??""))break;let E=Vs(e[o+c+1],i);if(E===void 0||E.kind!==i||E.ratio>=a)break;s+=Number(N.text)*E.ratio,a=E.ratio,l=E.spelling,u=e[o+c+1],c+=2;}if(c===2)return null;let f=e.slice(o,o+c),T=s/a;return {consumed:c,replacement:[chunkZSLVLMO5_cjs.b("NUMBER",String(T),f),chunkZSLVLMO5_cjs.b("UNIT",l,[u])],ruleName:"uom:compound-quantity"}}}}function Gs(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}function zs(t=59){return {name:"uom:two-unit-conversion",priority:t,shape:[{types:["IN","TO"]},{types:["UNIT"]}],match(e,o){let r=e[o];if(r?.type!=="IN"&&r?.type!=="TO"||!Gs(e[o+1])||e[o+2]?.type!=="AND_CONJ"||!Gs(e[o+3]))return null;let n=e[o+1].value,i=e[o+3].value;return {consumed:4,replacement:[chunkZSLVLMO5_cjs.b("IN_TWO_UNITS",`${n} ${i}`,e.slice(o,o+4))],ruleName:"uom:two-unit-conversion"}}}}function Ks(t=74){return {name:"uom:degree-symbol",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["\xB0"]}],match(e,o){let r=e[o];if(r?.type!=="NUMBER")return null;let n=e[o+1];return n===void 0||n.type!=="IDENT"||(n.text??n.value??"")!=="\xB0"?null:{consumed:2,replacement:[r,chunkZSLVLMO5_cjs.b("UNIT","degrees",[n])],ruleName:"uom:degree-symbol"}}}}var Nr=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let[i,a]=String(r.value).split(" ");n.emitOpcode(13),n.emitString(i),n.emitOpcode(13),n.emitString(a),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(3);}};function $s(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var On=new Set(["per","a","an","each","every"]);function $c(t){if(t===void 0||t.type!=="IDENT")return false;let e=(t.text??t.value??"").toLowerCase();return On.has(e)?false:/^[a-z][a-z_]{2,}$/.test(e)&&chunkEZKR44MA_cjs.a[e]===void 0}function Ws(t=75){return {name:"uom:bare-rate-denominator",priority:t,shape:[{types:["NUMBER","SLASH","IDENT"]},{types:["IDENT","UNIT"]}],match(e,o){let r=e[o];if(r===void 0)return null;if(r.type==="NUMBER"&&$c(e[o+1])){let l=e[o+1],u=e[o+2];if((u?.type==="SLASH"||u?.type==="IDENT"&&On.has((u.text??u.value??"").toLowerCase()))&&$s(e[o+3]))return {consumed:2,replacement:[r,chunkZSLVLMO5_cjs.b("UNIT",l.value,[l])],ruleName:"uom:bare-rate-denominator"}}if(!$s(e[o+1]))return null;let n=r.type==="SLASH",i=(r.text??r.value??"").toLowerCase(),a=r.type==="IDENT"&&On.has(i);if(!n&&!a)return null;let s=e[o+1];return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b("PER_UNIT",s.value,[r,s])],ruleName:"uom:bare-rate-denominator"}}}}var yr=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){n.emitOpcode(13),n.emitString(String(r.value)),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};var gr=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};function Wc(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var Yc=new Set(["per","a","an","each","every"]);function jc(t,e){for(let o=e;o<t.length&&o<e+5;o++){let r=t[o];if(r.type==="PER_UNIT")return true;if(r.type==="EOF"||r.type==="COMMA"||r.type==="RATE_AT")return false;if(r.type==="UNIT"&&chunkZKFCKAIX_cjs.i(r.value??void 0))return true;let n=(r.text??r.value??"").toLowerCase();if((r.type==="SLASH"||r.type==="IDENT"&&Yc.has(n))&&Wc(t[o+1]))return true}return false}function Ys(t=73){return {name:"uom:at-rate",priority:t,shape:[{types:["RATE_AT"]}],match(e,o){return e[o]?.type!=="RATE_AT"||!jc(e,o+1)?null:{consumed:1,replacement:[chunkZSLVLMO5_cjs.b("AT_RATE","at",[e[o]])],ruleName:"uom:at-rate"}}}}function Xc(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var Qc=new Set(["a","an"]);function js(t=76){return {name:"uom:for-duration",priority:t,shape:[{types:["FOR_DURATION"]},{types:["IDENT"]}],match(e,o){let r=e[o];if(r?.type!=="FOR_DURATION")return null;let n=e[o+1];return n?.type!=="IDENT"||!Qc.has((n.text??n.value??"").toLowerCase())||!Xc(e[o+2])?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("STAR","*",[r]),chunkZSLVLMO5_cjs.b("NUMBER","1",[n]),e[o+2]],ruleName:"uom:for-duration"}}}}function Cn(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var qc=new Set(["a","an"]);function Xs(t=61){return {name:"uom:reversed-conversion",priority:t,shape:[{types:["UNIT"]},{types:["IN"]}],match(e,o){if(o!==0||!Cn(e[o])||e[o+1]?.type!=="IN")return null;let r=e[o],n=e[o+2];if(n===void 0)return null;if(n.type==="NUMBER"&&Cn(e[o+3]))return {consumed:4,replacement:[n,e[o+3],e[o+1],r],ruleName:"uom:reversed-conversion"};let i=(n.text??n.value??"").toLowerCase();return n.type==="IDENT"&&qc.has(i)&&Cn(e[o+3])?{consumed:4,replacement:[chunkZSLVLMO5_cjs.b("NUMBER","1",[n]),e[o+3],e[o+1],r],ruleName:"uom:reversed-conversion"}:null}}}var Zc={water:1,milk:1.03,"whole milk":1.03,"skim milk":1.035,buttermilk:1.03,"heavy cream":1,"whipping cream":1,"sour cream":.96,yogurt:1.03,"greek yogurt":1.05,"cream cheese":1.01,"condensed milk":1.3,"evaporated milk":1.06,"coconut milk":.97,"almond milk":1.03,"soy milk":1.03,butter:.9595,margarine:.96,"vegetable oil":.92,"olive oil":.913,"canola oil":.92,"coconut oil":.92,"sunflower oil":.92,"sesame oil":.92,mayonnaise:.91,sugar:.845,"granulated sugar":.845,"brown sugar":.93,"powdered sugar":.51,"icing sugar":.51,honey:1.42,"maple syrup":1.32,"corn syrup":1.38,molasses:1.4,nutella:1.14,"peanut butter":1.09,flour:.53,"all-purpose flour":.53,"all purpose flour":.53,"bread flour":.54,"cake flour":.47,"whole wheat flour":.55,cornstarch:.53,cornmeal:.65,semolina:.6,rice:.79,"white rice":.79,"brown rice":.8,oats:.34,"rolled oats":.38,breadcrumbs:.43,yeast:.68,"dry yeast":.68,salt:1.2,"table salt":1.2,"kosher salt":.96,"baking powder":.9,"baking soda":.99,"cream of tartar":.68,cinnamon:.56,ginger:.5,"vanilla extract":.88,"lemon juice":1.03,"lime juice":1.02,"orange juice":1.04,vinegar:1.01,cocoa:.41,"cocoa powder":.41,"chocolate chips":.72,"chocolate chunks":.72,coconut:.35,"shredded coconut":.35,raisins:.68,almonds:.55,walnuts:.5,pecans:.5,pistachios:.55,peanuts:.6,"shredded cheese":.4,parmesan:.44,"tomato paste":1.06,"tomato sauce":1.02,ketchup:1.14,broth:1,stock:1,wine:.99,beer:1.01},Qs=2;function qs(t){return Zc[t.toLowerCase().trim()]}var Pr="cookingConvert";function Zs(t){let e=t[0],o=t[1].value,r=t[2].value;if(e.type!==6||!e.unit)return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_REQUIRES_UNIT",'Expected a value with a mass or volume unit (e.g. "300g", "10 cups"), got a plain number');let n=e.unit,i=e.toNumber(),a=chunkZKFCKAIX_cjs.c(n),s=chunkZKFCKAIX_cjs.c(r),l=N=>N==="mass"||N==="volume";if(!l(a))return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_UNSUPPORTED_UNIT",`"${n}" is not a recognized mass or volume unit`);if(!l(s))return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_UNSUPPORTED_UNIT",`"${r}" is not a recognized mass or volume unit`);if(a===s)return chunkGJZIJK2Q_cjs.u(chunkZKFCKAIX_cjs.e(i,n,r),r);let u=qs(o);if(u===void 0)return chunkGJZIJK2Q_cjs.P("COOKING_UNKNOWN_INGREDIENT",`No density data for "${o}" \u2014 cannot convert between mass and volume for this ingredient`);if(a==="mass"){let E=chunkZKFCKAIX_cjs.e(i,n,"g")/u,P=chunkZKFCKAIX_cjs.e(E,"ml",r);return chunkGJZIJK2Q_cjs.u(P,r)}let f=chunkZKFCKAIX_cjs.e(i,n,"ml")*u,T=chunkZKFCKAIX_cjs.e(f,"g",r);return chunkGJZIJK2Q_cjs.u(T,r)}var _r=class{constructor(){this.category="UoM";this.bindingPower=35;}parse(e,o,r,n){let i=r.value;e.consume("IN");let a=e.consume();n.emitOpcode(13),n.emitString(i),n.emitOpcode(13),n.emitString(a.value),n.emitPluginCall(Pr,3);}};function Js(t=68){return {name:"uom-cooking:ingredient-name",priority:t,shape:[{types:["IDENT"]}],match(e,o){let r=e[o-1];if(!r||r.type!=="UNIT")return null;for(let n=Qs;n>=1;n--){if(o+n>e.length)continue;let i=e.slice(o,o+n);if(!i.every(c=>c.type==="IDENT"))continue;let a=o+n,s=e[a];if(!s||s.type!=="IN")continue;let l=e[a+1];if(!l||l.type!=="UNIT"&&l.type!=="IDENT")continue;let u=i.map(c=>c.value.toLowerCase()).join(" ");return {consumed:n,replacement:[chunkZSLVLMO5_cjs.b("INGREDIENT_NAME",u,i)],ruleName:"uom-cooking:ingredient-name"}}return null}}}function em(t=78){return {name:"uom:multi-word-unit",priority:t,shape:[{types:["UNIT"]},{types:["UNIT"]}],match(e,o){let r=e[o],n=e[o+1];if(r?.type!=="UNIT"||n?.type!=="UNIT"||r.offset+r.text.length+1!==n.offset)return null;let i=`${r.value} ${n.value}`;return chunkEZKR44MA_cjs.a[i]===void 0?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("UNIT",i,e.slice(o,o+2))],ruleName:"uom:multi-word-unit"}}}}function tm(t=77){return {name:"uom:compound-unit",priority:t,shape:[{types:["UNIT"]},{types:["SLASH"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];if(r?.type!=="UNIT"||n?.type!=="SLASH"||i?.type!=="UNIT")return null;let a=`${r.value}/${i.value}`;return {consumed:3,replacement:[chunkZSLVLMO5_cjs.b("UNIT",a,[r,n,i])],ruleName:"uom:compound-unit"}}}}var In={name:"solve-uom",prefixParselets:{CONVERT:new Er,UOM_POSSIBILITIES_QUERY:new Tr},infixParselets:{IN_TWO_UNITS:new Nr(94),PER_UNIT:new yr(95),AT_RATE:new gr(96),UNIT:new dr,INGREDIENT_NAME:new _r},normalizerRules:[em(),tm(),Ds(),Hs(),zs(),Ks(),Ys(),js(),Ws(),Xs(),Js()],pluginFunctions:{[Pr]:Zs}};var Z=class{constructor(){this.category="UoM";}parse(e,o,r){let n=chunkFDKTESBC_cjs.ta(o.value)??o.value.toUpperCase();e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),e.peek()?.type==="UNIT"&&e.consume(),r.emitOpcode(13),r.emitString(n),r.emitOpcode(80);}};var xr=class{constructor(){this.category="UoM";this.bindingPower=35;}parse(e,o,r,n){let i=e.peek();if(i?.type==="IP_CIDR"){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,n),n.emitPluginCall("ipInCidr",2);return}if(i&&(i.type==="UNIT"||i.type==="DOLLAR"||i.type==="POUND"||i.type==="EURO"||i.type==="YEN"||i.type==="RUBLE"||i.type==="WON"||i.type==="CURRENCY_SYMBOL"||i.type==="IDENT"||i.type==="CITY_NAME"||i.type==="IN")){e.consume();let a=chunkFDKTESBC_cjs.ta(i.value)??i.value,s=fr(e,a);if(s!==null){n.emitOpcode(13),n.emitString(a),n.emitOpcode(13),n.emitString(s),n.emitPluginCall(Ee,3);return}n.emitOpcode(13),n.emitString(a),n.emitOpcode(84);}}};function hn(t={}){return {name:"solve-currency",asyncResolvers:[new chunkG2V33LFM_cjs.b,Ms(t.historicalRateProvider)],prefixParselets:{DOLLAR:new Z,POUND:new Z,EURO:new Z,YEN:new Z,RUBLE:new Z,WON:new Z,CURRENCY_SYMBOL:new Z},infixParselets:{IN:new xr},pluginFunctions:{[Ee]:An(t.historicalRateProvider)}}}var Sn=hn();var Le=class{constructor(e=0){this.category="Vector";this.dimension=e;}parse(e,o,r){e.consume("LPAREN");let n=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(0,r),n++;e.match("COMMA");)e.parseExpression(0,r),n++;e.consume("RPAREN"),r.emitOpcode(152),r.emitIndex(1),r.emitIndex(this.dimension>0?this.dimension:n);}};var Ar=class{constructor(){this.category="Float";}parse(e,o,r){e.consume("LPAREN"),e.parseExpression(0,r),e.consume("RPAREN"),r.emitOpcode(152),r.emitIndex(1),r.emitIndex(1);}};var Ln={name:"solve-vector",prefixParselets:{VEC2:new Le(2),VEC3:new Le(3),VEC4:new Le(4),FLOAT:new Ar}};var Rr=class{constructor(){this.category="Matrix";}parse(e,o,r){let n=0,i=-1;if(e.peek()?.type==="RBRACKET")throw chunkGXO7TSXQ_cjs.c.parsing("EMPTY_MATRIX_LITERAL","A matrix literal cannot be empty \u2014 `[]` has no valid shape.",{});for(;;){let a=0;for(e.parseExpression(0,r),a++;e.match("COMMA");)e.parseExpression(0,r),a++;if(i===-1)i=a;else if(a!==i)throw chunkGXO7TSXQ_cjs.c.parsing("RAGGED_MATRIX_LITERAL",`Matrix literal rows must all have the same number of columns \u2014 row ${n+1} has ${a}, but a previous row has ${i}.`,{expectedCols:i,actualCols:a,row:n+1});if(n++,!e.match("SEMICOLON"))break}e.consume("RBRACKET"),r.emitOpcode(152),r.emitIndex(n),r.emitIndex(i);}};var Or=class{constructor(){this.category="Matrix";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){let i=this.hasTopLevelColon(e);this.parseIndexArg(e,n,i);let a=1;if(e.match("COMMA")&&(this.parseIndexArg(e,n,i),a=2),e.consume("RBRACKET"),!i){a===1?n.emitOpcode(153):n.emitOpcode(154);return}if(a!==2)throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_MATRIX_SLICE_ARITY",`Range-based matrix slicing needs exactly 2 arguments ("a[rowRange, colRange]"), got ${a}.`,{argCount:a});n.emitOpcode(155);}hasTopLevelColon(e){let o=0;for(let r=0;;r++){let n=e.peekAt(r);if(!n)return false;if(n.type==="LBRACKET"||n.type==="LPAREN")o++;else if(n.type==="RBRACKET"||n.type==="RPAREN"){if(o===0)return false;o--;}else if(n.type==="COLON"&&o===0)return true}}parseIndexArg(e,o,r){e.parseExpression(0,o);let n=false;e.match("COLON")&&(e.parseExpression(0,o),n=true),r&&(n||o.emitOpcode(3),o.emitOpcode(156));}};var vn={name:"solve-matrix",prefixParselets:{LBRACKET:new Rr},infixParselets:{LBRACKET:new Or}};function Cr(t,e){let o=t.peek(),r=t.peekAt(1);if(o&&(o.type==="IDENT"||o.type==="UNIT"||o.type==="FUNC")&&r?.type==="COMMA"){t.consume();let a=o.value,s=an[a.toLowerCase()];return s!==void 0?{kind:1,builtinIdx:s}:{kind:2,name:a}}let n=new chunkZDJTDFTR_cjs.d(e.pluginIndexMap);t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),t.setBuilder(e);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","map/reduce transform expressions must be synchronous (no weather/stocks/currency calls).");return {kind:0,program:i}}function rm(t){let e=t.peek(),o=t.peekAt(1);return !!e&&(e.type==="IDENT"||e.type==="UNIT")&&o?.type==="EQUALS"}function om(t){let e=t.peek();if(e&&(e.type==="IDENT"||e.type==="UNIT"))return t.consume(),e.value;throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_EXPECTED_COLLECTION_NAME",`Expected a collection name (e.g. "x" in "x=[1,2,3]") but got ${e?`"${e.value}"`:"end of input"}.`)}function te(t,e){t.parseExpression(0,e),t.match("COLON")&&(t.parseExpression(0,e),e.emitOpcode(156));}function le(t,e,o,r,n){if(t.emitOpcode(e),t.emitIndex(o.kind),o.kind===0){let i=t.emitAnonymousBody(r,o.program);t.emitIndex(i);}else o.kind===1?t.emitIndex(o.builtinIdx):t.emitString(o.name);t.emitIndex(n);}var Ir=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=Cr(e,r);e.consume("COMMA");let i=[];if(rm(e))do{let a=om(e);e.consume("EQUALS"),te(e,r),i.push(a);}while(e.match("COMMA"));else te(e,r),i.push("x");e.consume("RPAREN"),le(r,157,n,i,i.length);}};var hr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=Cr(e,r);e.consume("COMMA"),te(e,r);let i=0;e.match("COMMA")&&(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i=1),e.consume("RPAREN"),le(r,158,n,["acc","x"],i);}};var Sr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);n.emitOpcode(60),n.emitString("acc"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),e.setBuilder(r),n.emitOpcode(20);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","sum's element expression must be synchronous (no weather/stocks/currency calls).");e.consume("COMMA"),te(e,r),e.consume("RPAREN"),r.emitOpcode(10),r.emitNumber(0),le(r,158,{kind:0,program:i},["acc","x"],1);}};var Lr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);n.emitOpcode(60),n.emitString("acc"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),e.setBuilder(r),n.emitOpcode(22);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","prod's element expression must be synchronous (no weather/stocks/currency calls).");e.consume("COMMA"),te(e,r),e.consume("RPAREN"),r.emitOpcode(10),r.emitNumber(1),le(r,158,{kind:0,program:i},["acc","x"],1);}};var nm={map:"MAP",reduce:"REDUCE",sum:"SUM_FN",prod:"PROD_FN"};function Jc(t,e){return t?!!(t.type==="LINE_REF"||t.type==="IDENT"&&(/^line\d+$/i.test(t.value)||/^line$/i.test(t.value)&&e?.type==="NUMBER"&&/^\d+$/.test(e.value))):false}function im(t=80){return {name:"mapreduce:call",priority:t,shape:[{types:["IDENT"],values:Object.keys(nm)},{types:["LPAREN"]}],match(e,o){let r=e[o];if(!r||r.type!=="IDENT")return null;let n=r.value.toLowerCase(),i=nm[n];return !i||e[o+1]?.type!=="LPAREN"||n==="sum"&&Jc(e[o+2],e[o+3])?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(i,chunkYBQOQTVL_cjs.c(i),r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"mapreduce:call"}}}}var wn={name:"solve-mapreduce",normalizerRules:[im()],prefixParselets:{MAP:new Ir,REDUCE:new hr,SUM_FN:new Sr,PROD_FN:new Lr}};var vr=class{constructor(){this.category="BigInt";}parse(e,o,r){r.emitOpcode(11),r.emitString(chunkZDJTDFTR_cjs.e(o.value,e.getLocaleCode()));}};var kn={name:"solve-bigint",prefixParselets:{BIGINT:new vr}};var re=class{constructor(e){this.opcode=e;this.category="Conditionals";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(this.opcode);}};var ve=class{constructor(e,o){this.opcode=e;this.bindingPower=o;this.category="Conditionals";}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(this.opcode);}};var mt=class{constructor(e){this.value=e;this.category="Conditionals";}parse(e,o,r){r.emitOpcode(14),r.emitByte(this.value?1:0);}};var wr=class{constructor(){this.category="Conditionals";}parse(e,o,r){e.parseExpression(0,r),e.consume("THEN"),e.parseExpression(0,r),e.consume("ELSE"),e.parseExpression(0,r),r.emitOpcode(132);}};var Bn={name:"solve-conditionals",prefixParselets:{TRUE:new mt(true),FALSE:new mt(false),IF:new wr},infixParselets:{EQUALITY:new re(40),NEQ:new re(41),LT:new re(42),GT:new re(44),LTE:new re(43),GTE:new re(45),OR:new ve(131,chunkZDJTDFTR_cjs.a.LogicalOr),LOGICAL_AND:new ve(130,chunkZDJTDFTR_cjs.a.LogicalAnd),LOGICAL_OR:new ve(131,chunkZDJTDFTR_cjs.a.LogicalOr)}};var ep={percent:74,percentage:74,decimal:70,dec:70,number:70,hex:71,fraction:140,multiplier:141,x:141,sci:142,scientific:142,binary:143,bin:143,octal:144,oct:144},am={2:143,8:144,16:71},kr=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=e.peek();if(i?.type==="PERCENT"){e.consume(),n.emitOpcode(74);return}if(!i||i.type!=="CONVERTER_NAME"&&i.type!=="IDENT"&&i.type!=="FUNC"&&i.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("AS_CONVERTER_EXPECTED_NAME",`Expected a converter name after "as" (e.g. "as hex", "as decimal") but got ${i?`"${i.value}"`:"end of input"}`);e.consume();let a=i.value.toLowerCase();if(a==="base"){let l=e.peek(),u=l?.type==="NUMBER"?Number(l.value):NaN,c=am[u];if(c===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("AS_CONVERTER_UNSUPPORTED_BASE",`"as base ${l?.value??"?"}": only bases ${Object.keys(am).join(", ")} can be written out`);e.consume(),n.emitOpcode(c);return}let s=ep[a];if(s!==void 0){s===141&&e.match("OF")&&(e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(23)),n.emitOpcode(s);return}n.emitOpcode(13),n.emitString(a),n.emitOpcode(145);}};var sm={ten:10,hundred:100,thousand:1e3,million:1e6,billion:1e9};function mm(t,e,o){t.emitOpcode(10),t.emitNumber(e),t.emitOpcode(23),lm(t,o),t.emitOpcode(10),t.emitNumber(e),t.emitOpcode(22);}function lm(t,e){let o=e==="up"?rp:e==="down"?op:tp;t.emitOpcode(51),t.emitIndex(o),t.emitIndex(1);}var tp=8,rp=6,op=7,np=97;function ip(t){let o=(t.peek()?.text??"").toLowerCase();return o==="up"?(t.consume(),"up"):o==="down"?(t.consume(),"down"):"nearest"}var Br=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=ip(e);if(e.match("TO_NEAREST")){mm(n,um(e),i);return}lm(n,i);}},Mr=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){mm(n,um(e),"nearest");}};function um(t){let e=t.peek(),o=(e?.text??"").toLowerCase(),r=sm[o];if(r!==void 0)return t.consume(),r;if(e?.type==="NUMBER"){t.consume();let n=Number(e.value);if(Number.isFinite(n)&&n>0)return n}throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_ROUNDING_INCREMENT",`"to nearest ${e?.value??"?"}": expected a positive number or one of ${Object.keys(sm).join(", ")}`)}var Ur=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=Number(r.value);if(!Number.isFinite(i)||i<0||i>100)throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_DECIMAL_PLACES",`"to ${r.value} dp": expected a place count between 0 and 100`);n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(51),n.emitIndex(np),n.emitIndex(2);}};var ap=new Set(["dp","dps","decimals","digits","digit"]),sp=new Set(["decimal"]);function cm(t=66){return {name:"converters:decimal-places",priority:t,shape:[{types:["TO"]},{types:["NUMBER"]}],match(e,o){if(e[o]?.type!=="TO")return null;let r=e[o+1];if(r?.type!=="NUMBER")return null;let n=e[o+2];if(!n)return null;let i=(n.text??n.value??"").toLowerCase(),a=3;if(sp.has(i)){let l=(e[o+3]?.text??"").toLowerCase();if(l!=="place"&&l!=="places")return null;a=4;}else if(!ap.has(i))return null;return {consumed:a,replacement:[chunkZSLVLMO5_cjs.b("DECIMAL_PLACES",r.value,e.slice(o,o+a))],ruleName:"converters:decimal-places"}}}}var mp=new Set(["hex","bin"]);function pm(t=67){return {name:"converters:preposition",priority:t,shape:[{types:["IN","TO"]},{types:["CONVERTER_NAME","FUNC"]}],match(e,o){let r=e[o];if(r?.type!=="IN"&&r?.type!=="TO")return null;let n=e[o+1];return n?.type==="CONVERTER_NAME"||n?.type==="FUNC"&&mp.has(n.value.toLowerCase())?{consumed:1,replacement:[chunkZSLVLMO5_cjs.b("AS","as",[r])],ruleName:"converters:preposition"}:null}}}var Mn={name:"solve-converters",phrases:{"to nearest":"TO_NEAREST","to the nearest":"TO_NEAREST"},infixParselets:{AS:new kr,ROUNDED:new Br,TO_NEAREST:new Mr,DECIMAL_PLACES:new Ur},normalizerRules:[cm(),pm()]};var G=class{constructor(e){this.builtinIndex=e;this.category="MathPhrases";}parse(e,o,r){let n=0;for(e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++;e.match("COMMA")||e.match("AND_CONJ");)e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++;r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(n);}};var Dr=class{constructor(e){this.builtinIndex=e;this.category="MathPhrases";}parse(e,o,r){let n=0;do{if(e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++,!e.match("RATE_AT")&&!e.match("AT")){let i=e.peek();throw chunkGXO7TSXQ_cjs.c.parsing("WEIGHTED_AVERAGE_MISSING_WEIGHT",'weighted average: each value needs a weight, as in "72 at 30%"',{actualType:i?.type,actualValue:i?.value})}e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),n++,this.skipWeightLabel(e);}while(e.match("COMMA")||e.match("AND_CONJ"));r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(n);}skipWeightLabel(e){for(;;){let o=e.peek();if(!o)return;if(o.type==="STAR"||o.type==="IDENT"||o.type==="UNIT"){e.consume();continue}return}}};function Un(t){return {category:"MathPhrases",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(t),r.emitIndex(1);}}}var dm={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),!t.match("DIVIDE_BY")&&!t.match("SLASH"))throw chunkGXO7TSXQ_cjs.c.parsing("REMAINDER_EXPECTED_DIVIDED_BY",'Expected "divided by" or "/", as in "remainder of 21 divided by 5"');t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),o.emitOpcode(24);}},Em={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),!t.match("OF"))throw chunkGXO7TSXQ_cjs.c.parsing("ROOT_EXPECTED_OF",'Expected "of", as in "root 5 of 100"');t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),o.emitOpcode(2),o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(2),o.emitOpcode(23),o.emitOpcode(25);}},Tm={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),fm(o),!t.match("LOG_BASE"))throw chunkGXO7TSXQ_cjs.c.parsing("LOG_EXPECTED_BASE",'Expected "base", as in "log 20 base 4"');t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),fm(o),o.emitOpcode(23);}},lp=5;function fm(t){t.emitOpcode(51),t.emitIndex(lp),t.emitIndex(1);}function Nm(t=69){return {name:"mathphrases:function-phrase",priority:t,shape:[{types:["FUNC"],values:["root","log"]}],match(e,o){let r=e[o];if(r?.type!=="FUNC")return null;let n=(r.value??"").toLowerCase();if(n!=="root"&&n!=="log"||e[o+1]?.type==="LPAREN")return null;if(n==="root")return {consumed:1,replacement:[chunkZSLVLMO5_cjs.b("NTH_ROOT","root",[r])],ruleName:"mathphrases:function-phrase"};let i=up(e,o+1);if(i===-1)return null;let a=e.slice(o,i+1).map((s,l)=>l===0?chunkZSLVLMO5_cjs.b("LOG_PHRASE","log",[s]):l===i-o?chunkZSLVLMO5_cjs.b("LOG_BASE","base",[s]):s);return {consumed:i-o+1,replacement:a,ruleName:"mathphrases:function-phrase"}}}}function up(t,e){for(let o=e;o<t.length&&o<e+8;o++){let r=t[o];if(r.type==="EOF"||r.type==="COMMA"||r.type==="RPAREN")return -1;if((r.text??r.value??"").toLowerCase()==="base")return o}return -1}function lt(t){return {category:"MathPhrases",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(t),r.emitIndex(2);}}}var ym={category:"MathPhrases",parse(t,e,o){t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),o.emitOpcode(10),o.emitNumber(2),o.emitOpcode(23);}};var gm={category:"MathPhrases",parse(t,e,o){t.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,o),t.consume("AND_CONJ"),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),o.emitOpcode(20),o.emitOpcode(10),o.emitNumber(2),o.emitOpcode(23);}};var Pm=ar({category:"MathPhrases",alternatives:[{slots:[{kind:"keyword",tokenTypes:["BETWEEN"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["AND_CONJ"]},{kind:"expr"}],emit:t=>{t.emitOpcode(51),t.emitIndex(37),t.emitIndex(2);}}]});var cp=47,br=class{constructor(){this.category="MathPhrases";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let n=e.peek();if(n?.type==="BETWEEN")e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);else if(n?.type==="FROM")e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("TO"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);else throw chunkGXO7TSXQ_cjs.c.parsing("CLAMP_EXPECTED_BETWEEN_OR_FROM",`Expected "between" or "from" after "clamp <value>" but got ${n?`"${n.value}"`:"end of input"}`);r.emitOpcode(51),r.emitIndex(cp),r.emitIndex(3);}};var pp=46,Vr=class{constructor(){this.category="MathPhrases";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),e.consume("AS"),e.parseExpression(this.bindingPower,n),e.consume("IS_TO");let i=e.consume();if(!i||i.value.toLowerCase()!=="what")throw chunkGXO7TSXQ_cjs.c.parsing("PROPORTION_EXPECTED_WHAT",`Expected "what" but got ${i?`"${i.value}"`:"end of input"}`);n.emitOpcode(51),n.emitIndex(pp),n.emitIndex(3);}};var fp=42,dp=43,Ep=44,Tp=45,Np=9,yp=10,gp=101,Pp=102,_p=103,xp=104,Ap=105,Rp=106,Op=107,Cp=38,Ip=39,hp=0,Sp=21,Dn={name:"solve-mathphrases",phrases:{"average of":"AVERAGE_OF","median of":"MEDIAN_OF","total of":"TOTAL_OF","count of":"COUNT_OF","larger of":"LARGER_OF","greater of":"LARGER_OF","smaller of":"SMALLER_OF","lesser of":"SMALLER_OF","half of":"HALF_OF","midpoint between":"MIDPOINT_BETWEEN","random number":"RANDOM_NUMBER","is to":"IS_TO","remainder of":"REMAINDER_OF","gcd of":"GCD_OF","lcm of":"LCM_OF","square root of":"SQUARE_ROOT_OF","cube root of":"CUBE_ROOT_OF","standard deviation of":"STANDARD_DEVIATION_OF","stdev of":"STANDARD_DEVIATION_OF","sample standard deviation of":"SAMPLE_STANDARD_DEVIATION_OF","sample stdev of":"SAMPLE_STANDARD_DEVIATION_OF","variance of":"VARIANCE_OF","sample variance of":"SAMPLE_VARIANCE_OF","spread of":"SPREAD_OF","mode of":"MODE_OF","weighted average of":"WEIGHTED_AVERAGE_OF","weighted mean of":"WEIGHTED_AVERAGE_OF"},prefixParselets:{AVERAGE_OF:new G(fp),MEDIAN_OF:new G(dp),TOTAL_OF:new G(Ep),COUNT_OF:new G(Tp),LARGER_OF:lt(yp),SMALLER_OF:lt(Np),HALF_OF:ym,MIDPOINT_BETWEEN:gm,RANDOM_NUMBER:Pm,REMAINDER_OF:dm,NTH_ROOT:Em,LOG_PHRASE:Tm,GCD_OF:lt(Cp),LCM_OF:lt(Ip),SQUARE_ROOT_OF:Un(hp),CUBE_ROOT_OF:Un(Sp),CLAMP:new br,STANDARD_DEVIATION_OF:new G(gp),SAMPLE_STANDARD_DEVIATION_OF:new G(Pp),VARIANCE_OF:new G(_p),SAMPLE_VARIANCE_OF:new G(xp),SPREAD_OF:new G(Ap),MODE_OF:new G(Rp),WEIGHTED_AVERAGE_OF:new Dr(Op)},infixParselets:{IS_TO:new Vr},normalizerRules:[Nm()]};var _m={annually:1,yearly:1,"semi-annually":2,quarterly:4,monthly:12,fortnightly:26,weekly:52,daily:365};function bn(t){if(!t.match("COMPOUNDING"))return 1;let e=t.peek(),o=(e?.text??e?.value??"").toLowerCase(),r=_m[o];if(r===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("UNKNOWN_COMPOUNDING_INTERVAL",`compounding ${o||"?"}: expected one of ${Object.keys(_m).join(", ")}`);return t.consume(),r}var ut=class{constructor(e,o){this.annualIndex=e;this.intervalIndex=o;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n);let i=bn(e);if(n.emitOpcode(2),i===1){n.emitOpcode(51),n.emitIndex(this.annualIndex),n.emitIndex(3);return}n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(51),n.emitIndex(this.intervalIndex),n.emitIndex(4);}},Fr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),!e.match("AFTER")&&!e.match("OVER")&&!e.match("IN")&&e.consume("AFTER"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),r.emitOpcode(2),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}},Hr=class{constructor(e){this.builtinIndex=e;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.consume("RETURNED"),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}},Gr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("INVESTED"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("RETURNED"),!e.match("AFTER")&&!e.match("OVER")&&!e.match("IN")&&e.consume("AFTER"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}};function zr(t,e,o){return Am(t,o)?(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),xm(t),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),{swap:true}):(xm(t),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),Lp(t,o),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),{swap:false})}function Am(t,e){for(let o of e)if(t.match(o))return true;return false}function Lp(t,e){Am(t,e)||t.consume(e[0]);}function xm(t){t.match("RATE_AT")||t.consume("AT");}var ct=class{constructor(e,o){this.builtinIndex=e;this.intervalIndex=o;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r);let{swap:n}=zr(e,r,["AFTER","FOR_DURATION","OVER"]),i=bn(e);if(n&&r.emitOpcode(2),i===1){r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);return}r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(51),r.emitIndex(this.intervalIndex),r.emitIndex(4);}};var X=class{constructor(e,o){this.builtinIndex=e;this.periodsPerYear=o;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let{swap:n}=zr(e,r,["OVER"]);n&&r.emitOpcode(2),r.emitOpcode(10),r.emitNumber(this.periodsPerYear),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(4);}};var Kr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("BETWEEN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.match("PEOPLE"),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(2);}},$r=class{constructor(e){this.builtinIndex=e;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.consume("WAYS"),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};var Rm={daily:{perYear:365,unit:"days"},weekly:{perYear:52,unit:"weeks"},monthly:{perYear:12,unit:"months"},yearly:{perYear:1,unit:"years"},annually:{perYear:1,unit:"years"}};function vp(t){let e=t.peek(),o=(e?.text??e?.value??"").toLowerCase(),r=Rm[o];if(r===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("UNKNOWN_SAVINGS_PERIOD",`savings goal: expected a contribution period, one of ${Object.keys(Rm).join(", ")}, not "${o||"?"}".`);return t.consume(),r}var Wr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.match("STAR");let n=vp(e);r.emitOpcode(10),r.emitNumber(n.perYear),e.match("RATE_AT")||e.match("AT")?e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r):(r.emitOpcode(10),r.emitNumber(0)),r.emitOpcode(13),r.emitString(n.unit),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(5);}},Yr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.match("AT")?e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r):(r.emitOpcode(10),r.emitNumber(0)),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}};var we=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("RATE_AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(2);}};var wp=60;function kp(t){for(let e=0;;e++){let o=t.peekAt(e);if(!o)return false;if(o.type==="FROM"||o.type==="WORTH_IN")return true}}var pt=class{constructor(e){this.variant=e;this.category="Finance";}parse(e,o,r){if(!kp(e)){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);return}if(e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),this.variant==="what-was"){e.consume("WORTH_IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("inflationToYearFromPresent",2);return}let n=e.peek();if(n?.type==="FROM"){e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("inflationFromYearToPresent",2);return}if(n?.type==="IN"){e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("WORTH_IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(wp),r.emitIndex(3);return}let i=n?n.type:"end of input";throw chunkGXO7TSXQ_cjs.c.parsing("INFLATION_EXPECTED_FROM_OR_IN",`Expected "from <year>" or "in <year> worth in <year>" after "what is <amount>", got ${i}`)}};var jr=class{constructor(){this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("ASSUMING"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let n=e.peek();if((n&&n.type==="IDENT"?n.value.toLowerCase():void 0)!=="inflation"){let a=n?n.value:"end of input";throw chunkGXO7TSXQ_cjs.c.parsing("INFLATION_EXPECTED_INFLATION_WORD",`Expected the word "inflation" after "assuming <rate>%", got "${a}"`)}e.consume(),r.emitPluginCall("inflationFutureValue",3);}};var Xr=class{constructor(){this.category="Finance";this.bindingPower=35;}parse(e,o,r,n){let i=Number(r.value);n.emitOpcode(10),n.emitNumber(i),n.emitPluginCall("inflationToYearFromPresent",2);}};function Vn(t){let e=chunkTPPM4QSS_cjs.c(t);return e.fields(e.now()).year}function Om(t,e){return chunkGJZIJK2Q_cjs.P(t,`Year ${e} is outside the bundled CPI table's range (${chunkQQHHZPEW_cjs.z}-${chunkQQHHZPEW_cjs.A})`)}function Cm(t,e){let o=t[0],r=t[1].toNumber(),n=Vn(e),i=chunkQQHHZPEW_cjs.B(o.toNumber(),r,n);return i===void 0?Om("INFLATION_YEAR_OUT_OF_RANGE",r):o.type===6?chunkGJZIJK2Q_cjs.u(i,o.unit):chunkGJZIJK2Q_cjs.n(i)}function Im(t,e){let o=t[0],r=Vn(e),n=t[1].toNumber(),i=chunkQQHHZPEW_cjs.B(o.toNumber(),r,n);return i===void 0?Om("INFLATION_YEAR_OUT_OF_RANGE",n):o.type===6?chunkGJZIJK2Q_cjs.u(i,o.unit):chunkGJZIJK2Q_cjs.n(i)}function hm(t,e){let o=t[0],r=t[1].toNumber(),n=t[2].toNumber(),i=r-Vn(e);if(1+n<=0)return chunkGJZIJK2Q_cjs.P("INVALID_RATE",`inflationFutureValue: rate ${n} makes (1 + rate) non-positive`);let s=o.toNumber()/Math.pow(1+n,i);return o.type===6?chunkGJZIJK2Q_cjs.u(s,o.unit):chunkGJZIJK2Q_cjs.n(s)}function Sm(t=70){return {name:"finance:in-year-dollars",priority:t,shape:[{types:["IN"]},{types:["NUMBER"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];if(r.type!=="IN"||n?.type!=="NUMBER"||i?.type!=="IDENT"&&i?.type!=="UNIT")return null;let a=i.value.toLowerCase();return a!=="dollars"&&a!=="dollar"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("IN_YEAR_DOLLARS",n.value,e.slice(o,o+3))],ruleName:"finance:in-year-dollars"}}}}var Bp={RECURRING_INTERVAL_NOT_POSITIVE:"RECURRING_INTERVAL_NOT_POSITIVE"},Mp={daily:365,weekly:52,monthly:12,yearly:1,annually:1},Up={day:365,days:365,week:52,weeks:52,month:12,months:12,year:1,years:1},Dp=new Set(["a","an"]),bp=new Set(["NUMBER","FLOAT","HEX","BIGINT","RPAREN","RBRACKET","IDENT","PERCENT","STRING"]);function ft(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}function Lm(t){if(!(t===void 0||t.type!=="UNIT"))return Up[ft(t)]}function Vp(t,e){let o=t[e];if(o===void 0)return null;if(o.type==="IDENT"){let r=Mp[ft(o)];if(r!==void 0)return {perYear:r,consumed:1};if(ft(o)==="every"){let n=t[e+1];if(n?.type!=="NUMBER")return null;let i=Lm(t[e+2]);if(i===void 0)return null;let a=Number((n.value??"").replace(/,/g,""));if(!(a>0))throw chunkGXO7TSXQ_cjs.c.parsing({code:Bp.RECURRING_INTERVAL_NOT_POSITIVE,message:`A recurring interval must be a positive number, not "${n.value}".`,expected:"a positive interval, e.g. every 2 weeks",found:`every ${n.value} ${ft(t[e+2])}`});return {perYear:i/a,consumed:3}}}return null}function Fp(t,e){let o=t[e];if(o===void 0)return null;let r,n;if(o.type==="NUMBER")r=Number((o.value??"").replace(/,/g,"")),n=e+1;else if(o.type==="IDENT"&&Dp.has(ft(o)))r=1,n=e+1;else return null;let i=Lm(t[n]);return i===void 0||!Number.isFinite(r)||r<0?null:{years:r/i,consumed:n-e+1}}function Hp(t,e){let o=t*e,r=Math.round(o);return Math.abs(o-r)<1e-9?r:Math.floor(o)}function vm(t=78){return {name:"finance:recurring-schedule",priority:t,unshapedReason:"Scans forward through a period and a duration sub-grammar of unbounded length, so no fixed leading shape describes it.",match(e,o){let r=e[o];if(r===void 0||!bp.has(r.type))return null;let n=Vp(e,o+1);if(n===null)return null;let i=o+1+n.consumed;if(e[i]?.type!=="FOR_DURATION")return null;let a=Fp(e,i+1);if(a===null)return null;let s=Hp(n.perYear,a.years),l=i+1+a.consumed-o,u=e.slice(o,o+l);return {replacement:[r,chunkZSLVLMO5_cjs.b("STAR","*",u),chunkZSLVLMO5_cjs.b("NUMBER",String(s),u)],consumed:l,ruleName:"finance:recurring-schedule"}}}}function Qr(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}var wm=new Set(["NUMBER","FLOAT","HEX","BIGINT","RPAREN","RBRACKET","IDENT","PERCENT","STRING"]),km=new Set(["NUMBER","FLOAT"]);function Bm(t=77){return {name:"finance:bill-split",priority:t,unshapedReason:"Scans forward an unbounded distance for the BETWEEN keyword, and starts at any value-ending token.",match(e,o){let r=e[o];if(r===void 0)return null;if(wm.has(r.type)){let f=e[o+1],T=e[o+2],N=e[o+3];if(f?.type==="IDENT"&&Qr(f)==="split"&&T!==void 0&&km.has(T.type)&&N?.type==="IDENT"&&Qr(N)==="ways")return {consumed:4,replacement:[r,chunkZSLVLMO5_cjs.b("SPLIT_WAYS","split",[f]),T,chunkZSLVLMO5_cjs.b("WAYS","ways",[N])],ruleName:"finance:bill-split"}}if(r.type!=="IDENT"||Qr(r)!=="split")return null;let n=e[o-1];if(n!==void 0&&wm.has(n.type))return null;let i=-1;for(let f=o+1;f<e.length;f++)if(e[f].type==="BETWEEN"){i=f;break}if(i===-1)return null;let a=e[i+1];if(a===void 0||!km.has(a.type))return null;let s=i+2,l=e[s]?.type==="IDENT"&&Qr(e[s])==="people",u=l?s:i+1,c=[chunkZSLVLMO5_cjs.b("SPLIT","split",[r]),...e.slice(o+1,i+2)];return l&&c.push(chunkZSLVLMO5_cjs.b("PEOPLE","people",[e[s]])),{consumed:u-o+1,replacement:c,ruleName:"finance:bill-split"}}}}var Fn=51,Gp=52,qr=55,Zr=56,Hn=80,zp=81,Kp=82,$p=83,Wp=84,Yp=59,jp=85,Xp=86,Mm=98,Qp=99,qp=100,Gn={name:"solve-finance",phrases:{"compound interest on":"COMPOUND_INTEREST_ON","interest on":"INTEREST_ON","daily repayment on":"DAILY_REPAYMENT_ON","monthly repayment on":"MONTHLY_REPAYMENT_ON","annual repayment on":"ANNUAL_REPAYMENT_ON","total repayment on":"TOTAL_REPAYMENT_ON","daily interest on":"DAILY_LOAN_INTEREST_ON","monthly interest on":"MONTHLY_LOAN_INTEREST_ON","annual interest on":"ANNUAL_LOAN_INTEREST_ON","total interest on":"TOTAL_LOAN_INTEREST_ON","tax on":"TAX_ON","tax off":"TAX_OFF","tax in":"TAX_IN_PHRASE","tax of":"TAX_IN_PHRASE","tax from":"TAX_IN_PHRASE","vat in":"TAX_IN_PHRASE","vat of":"TAX_IN_PHRASE","vat from":"TAX_IN_PHRASE","vat on":"TAX_ON","vat off":"TAX_OFF","what is":"WHAT_IS","what was":"WHAT_WAS","present value of":"PRESENT_VALUE_OF","annual return on":"ANNUAL_RETURN_ON","value of":"VALUE_OF","worth in":"WORTH_IN","how long to save":"SAVINGS_HOW_LONG","how much per month to save":"SAVINGS_HOW_MUCH","how much per month to reach":"SAVINGS_HOW_MUCH",assuming:"ASSUMING"},prefixParselets:{PRESENT_VALUE_OF:new Fr(Kp),ANNUAL_RETURN_ON:new Gr(Wp),COMPOUND_INTEREST_ON:new ct(Fn,Hn),INTEREST_ON:new ct(Gp,zp),DAILY_REPAYMENT_ON:new X(qr,365),MONTHLY_REPAYMENT_ON:new X(qr,12),ANNUAL_REPAYMENT_ON:new X(qr,1),TOTAL_REPAYMENT_ON:new X(qr,0),DAILY_LOAN_INTEREST_ON:new X(Zr,365),MONTHLY_LOAN_INTEREST_ON:new X(Zr,12),ANNUAL_LOAN_INTEREST_ON:new X(Zr,1),TOTAL_LOAN_INTEREST_ON:new X(Zr,0),TAX_ON:new we(Xp),TAX_OFF:new we(Yp),TAX_IN_PHRASE:new we(jp),SPLIT:new Kr(Mm),WHAT_IS:new pt("what-is"),WHAT_WAS:new pt("what-was"),VALUE_OF:new jr,SAVINGS_HOW_LONG:new Wr(qp),SAVINGS_HOW_MUCH:new Yr(Qp)},infixParselets:{AFTER:new ut(Fn,Hn),FOR_DURATION:new ut(Fn,Hn),INVESTED:new Hr($p),IN_YEAR_DOLLARS:new Xr,SPLIT_WAYS:new $r(Mm)},normalizerRules:[Sm(),vm(),Bm()],pluginFunctions:{inflationFromYearToPresent:Cm,inflationToYearFromPresent:Im,inflationFutureValue:hm}};function Zp(t){return (e,o)=>chunkGJZIJK2Q_cjs.P(`${t.toUpperCase()}_QUERY_FAILED`,`Failed to resolve "${e}": ${o instanceof Error?o.message:String(o)}`)}function oe(t){let e=t.staleTimeMs??3e5,o=t.timeoutMs??1e4,r=t.failureCooldownMs??3e4,n=t.onError??Zp(t.namespace),i=u=>[t.namespace,u];async function a(u,c,f){let{signal:T,cleanup:N}=chunkTLG7VZRX_cjs.a(c,o,`${t.namespace} query`);try{return await t.fetchQuery(u,T)}catch(E){let P=n(u,E);return setTimeout(()=>{f.getQueryData(i(u))===P&&f.removeQueries({queryKey:i(u),exact:true});},r).unref?.(),P}finally{N();}}return {resolver:{namespace:t.namespace,preflight(u,c,f,T,N){let{opcodes:E,strings:P}=c,R=E.length,O=0;for(;O<R;){if(E[O]===50&&O+2<R){let _=E[O+1],h=E[O+2];if(_===t.pluginFunctionIndex&&h>=1&&O>=2&&E[O-2]===13){let S=P[E[O-1]],q=i(S);if(N.getQueryData(q)===void 0){let $e=N.fetchQuery({queryKey:q,queryFn:({signal:Ko})=>a(S,Ko,N),staleTime:e}),pe={queryKey:q.join(":"),resolver:$e,packageId:f,signal:T,metadata:{query:S}};return t.refetchIntervalMs!==void 0&&(pe.refetchIntervalMs=t.refetchIntervalMs,pe.refetch=()=>N.fetchQuery({queryKey:q,queryFn:({signal:Ko})=>a(S,Ko,N),staleTime:0})),pe}}O+=3;continue}O=chunkG2V33LFM_cjs.a(E,O);}return null},destroy(){}},pluginFunction:(u,c)=>{let f=u[0]?.value,T=chunkZLRJ7TDP_cjs.b()?.getQueryData(i(f));return T!==void 0?T:c?.networkEnabled===false?chunkGJZIJK2Q_cjs.P("NETWORK_DISABLED",`Live data is switched off for this engine (network.enabled is false), so "${f}" was not fetched`):chunkGJZIJK2Q_cjs.P(`${t.namespace.toUpperCase()}_NOT_PREFLIGHTED`,`No cached result for "${f}"`)}}}function Jp(t,e){let o=[];for(;t.peek()?.type==="IDENT";)o.push(t.consume().value);if(o.length===0)throw chunkGXO7TSXQ_cjs.c.parsing("WEATHER_EXPECTED_CITY",`Expected a city name after "${e}" (e.g. "${e} London")`);return o.join(" ")}function ke(t,e){return {category:"Weather",parse(o,r,n){let i=Jp(o,r.value);n.emitOpcode(13),n.emitString(`${t}:${i}`),n.emitPluginCall(e,1);}}}var ef={0:"clear sky",1:"mainly clear",2:"partly cloudy",3:"overcast",45:"fog",48:"depositing rime fog",51:"light drizzle",53:"moderate drizzle",55:"dense drizzle",56:"light freezing drizzle",57:"dense freezing drizzle",61:"slight rain",63:"moderate rain",65:"heavy rain",66:"light freezing rain",67:"heavy freezing rain",71:"slight snow fall",73:"moderate snow fall",75:"heavy snow fall",77:"snow grains",80:"slight rain showers",81:"moderate rain showers",82:"violent rain showers",85:"slight snow showers",86:"heavy snow showers",95:"thunderstorm",96:"thunderstorm with slight hail",99:"thunderstorm with heavy hail"};function Um(t){return ef[t]??`weather code ${t}`}var Be={GEOCODING_API_ERROR:"WEATHER_GEOCODING_API_ERROR",CITY_NOT_FOUND:"WEATHER_CITY_NOT_FOUND",FORECAST_API_ERROR:"WEATHER_FORECAST_API_ERROR",FORECAST_RESPONSE_MALFORMED:"WEATHER_FORECAST_RESPONSE_MALFORMED",UNKNOWN_QUERY_KIND:"WEATHER_UNKNOWN_QUERY_KIND"},tf="https://geocoding-api.open-meteo.com/v1/search",rf="https://api.open-meteo.com/v1/forecast",of=1e4;async function nf(t,e){let o=`${tf}?name=${encodeURIComponent(t)}&count=1&language=en&format=json`,r=await fetch(o,{signal:e});if(!r.ok)throw chunkGXO7TSXQ_cjs.c.external(Be.GEOCODING_API_ERROR,`Open-Meteo geocoding API returned ${r.status} for "${t}"`,{city:t,status:r.status});let i=(await r.json())?.results?.[0];if(!i)throw chunkGXO7TSXQ_cjs.c.validation(Be.CITY_NOT_FOUND,`No location found for "${t}"`,{city:t});return {latitude:i.latitude,longitude:i.longitude,name:i.name}}async function af(t,e,o){let r=new URLSearchParams({latitude:String(t),longitude:String(e),current:"temperature_2m,apparent_temperature,weather_code",daily:"temperature_2m_max,temperature_2m_min",timezone:"auto",forecast_days:"1"}),n=await fetch(`${rf}?${r.toString()}`,{signal:o});if(!n.ok)throw chunkGXO7TSXQ_cjs.c.external(Be.FORECAST_API_ERROR,`Open-Meteo forecast API returned ${n.status}`,{status:n.status});let i=await n.json(),a=i?.current,s=i?.daily;if(!a||!s)throw chunkGXO7TSXQ_cjs.c.external(Be.FORECAST_RESPONSE_MALFORMED,"Open-Meteo forecast response missing current/daily blocks");return {weatherCode:a.weather_code,temperature:a.temperature_2m,apparentTemperature:a.apparent_temperature,high:s.temperature_2m_max?.[0],low:s.temperature_2m_min?.[0]}}var Jr=new Map,sf=6e4;function Dm(t,e){let o=t.trim().toLowerCase(),r=Date.now(),n=Jr.get(o);if(n&&n.expiresAt>r)return n.promise;let{signal:i,cleanup:a}=chunkTLG7VZRX_cjs.a(e,of,"Open-Meteo weather query"),s=(async()=>{try{let l=await nf(t,i),u=await af(l.latitude,l.longitude,i);return {resolvedName:l.name,weatherCode:u.weatherCode,description:Um(u.weatherCode),temperature:u.temperature,apparentTemperature:u.apparentTemperature,high:u.high,low:u.low}}finally{a();}})();return Jr.set(o,{promise:s,expiresAt:r+sf}),s.catch(()=>{Jr.get(o)?.promise===s&&Jr.delete(o);}),s}var bm="solve-weather",Te="weather",mf=chunkQQHHZPEW_cjs.F(`${bm}:${Te}`),{resolver:lf,pluginFunction:uf}=oe({namespace:"weather",pluginFunctionIndex:mf,staleTimeMs:600*1e3,fetchQuery:async(t,e)=>{let o=t.indexOf(":"),r=o===-1?t:t.slice(0,o),n=o===-1?"":t.slice(o+1),i=await Dm(n,e);switch(r){case "current":return chunkGJZIJK2Q_cjs.t(`${Math.round(i.temperature)}\xB0C, ${i.description}`);case "temperature":return chunkGJZIJK2Q_cjs.u(i.temperature,"C");case "feelslike":return chunkGJZIJK2Q_cjs.u(i.apparentTemperature,"C");case "high":return chunkGJZIJK2Q_cjs.u(i.high,"C");case "low":return chunkGJZIJK2Q_cjs.u(i.low,"C");default:throw chunkGXO7TSXQ_cjs.c.internal(Be.UNKNOWN_QUERY_KIND,`Unknown weather query kind "${r}"`,{kind:r})}}}),zn={name:bm,phrases:{"weather in":"WEATHER_IN","temperature in":"TEMPERATURE_IN","feels like in":"FEELS_LIKE_IN","high in":"HIGH_IN","low in":"LOW_IN"},prefixParselets:{WEATHER_IN:ke("current",Te),TEMPERATURE_IN:ke("temperature",Te),FEELS_LIKE_IN:ke("feelslike",Te),HIGH_IN:ke("high",Te),LOW_IN:ke("low",Te)},pluginFunctions:{[Te]:uf},asyncResolvers:[lf]};var eo={jan:0,january:0,feb:1,february:1,mar:2,march:2,apr:3,april:3,may:4,jun:5,june:5,jul:6,july:6,aug:7,august:7,sep:8,sept:8,september:8,oct:9,october:9,nov:10,november:10,dec:11,december:11};function ro(t){return t<10?`0${t}`:String(t)}function dt(t,e,o,r,n){let i=n.fields(n.localMidnight(t,e,o));if(i.year!==t||i.month0!==e||i.day!==o)throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`"${r}" is not a valid calendar date`);return {isoDate:`${t}-${ro(e+1)}-${ro(o)}`,raw:r}}function to(t,e){if(!/^\d{4}$/.test(t))throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`Expected a 4-digit year in "${e}", got "${t}"`);return parseInt(t,10)}function Vm(t){let e=t.peek();if(!e)return null;let o=t.getCalendar();if(e.type==="DATETIME_LITERAL"){t.consume();let r=o.fields(Number(e.value));return Number.isNaN(r.year)?null:{isoDate:`${r.year}-${ro(r.month0+1)}-${ro(r.day)}`,raw:e.text??e.value}}if(e.type==="NUMBER"){let r=t.consume(),n=t.peek();if(n&&(n.type==="SLASH"||n.type==="MINUS")){let a=n.type;t.consume();let s=t.consume("NUMBER");t.consume(a);let l=t.consume("NUMBER"),u=`${r.value}${a==="SLASH"?"/":"-"}${s.value}${a==="SLASH"?"/":"-"}${l.value}`;if(a==="SLASH"){let c=parseInt(r.value,10),f=parseInt(s.value,10),T=to(l.value,u);return dt(T,c-1,f,u,o)}else {if(/^\d{4}$/.test(r.value)){let N=parseInt(r.value,10),E=parseInt(s.value,10),P=parseInt(l.value,10);return dt(N,E-1,P,u,o)}let c=parseInt(r.value,10),f=parseInt(s.value,10),T=to(l.value,u);return dt(T,c-1,f,u,o)}}let i=t.peek();if(i&&i.type==="IDENT"&&eo[i.value.toLowerCase()]!==void 0){let a=eo[i.value.toLowerCase()];t.consume(),t.peek()?.type==="COMMA"&&t.consume();let s=t.consume("NUMBER"),l=`${r.value} ${i.value} ${s.value}`,u=to(s.value,l);return dt(u,a,parseInt(r.value,10),l,o)}throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`Expected a date after "on" (e.g. "April 12, 2005" or "4/12/2005"), got "${r.value}"`)}if(e.type==="IDENT"&&eo[e.value.toLowerCase()]!==void 0){let r=eo[e.value.toLowerCase()];t.consume();let n=t.consume("NUMBER");t.peek()?.type==="COMMA"&&t.consume();let i=t.consume("NUMBER"),a=`${e.value} ${n.value}, ${i.value}`,s=to(i.value,a);return dt(s,r,parseInt(n.value,10),a,o)}return null}var Kn=new Set(["AAPL","MSFT","GOOGL","GOOG","AMZN","META","NVDA","TSLA","NFLX","ADBE","CRM","ORCL","IBM","INTC","AMD","CSCO","PYPL","UBER","ABNB","SPOT","SHOP","SQ","COIN","PLTR","SNOW","ZM","JPM","V","MA","BAC","WFC","GS","MS","AXP","WMT","COST","HD","NKE","SBUX","MCD","KO","PEP","DIS","TGT","BA","GE","F","GM","XOM","CVX","PFE","JNJ","UNH","MRNA","TSM","ASML","BABA"]);var Me="STOCK_TICKER",cf=chunkYBQOQTVL_cjs.c(Me);function Fm(){return {name:"stocks:bare-ticker",priority:20,shape:[{types:["IDENT"],values:[...Kn]}],match(t,e){let o=t[e];return !o||o.type!=="IDENT"||!Kn.has(o.value)||e>0&&t[e-1].type==="COLON"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(Me,cf,o.value,o.value,o.offset,0,o.line,o.col)],ruleName:"stocks:bare-ticker"}}}}function pf(t){let e=t.peek();if(!e||e.type!=="IDENT")return null;let o=e.value.toLowerCase(),r="close";if(o==="close"||o==="volume"){r=o,t.consume();let i=t.peek();if(!i||i.type!=="IDENT"||i.value.toLowerCase()!=="on")throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_EXPECTED_ON",`Expected "on <date>" after "${o}" (e.g. "AAPL ${o} on April 12, 2005")`);t.consume();}else if(o==="on")t.consume();else return null;let n=Vm(t);if(!n)throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_EXPECTED_DATE",'Expected a date after "on" (e.g. "April 12, 2005" or "4/12/2005")');return {field:r,date:n}}function Hm(t,e,o,r,n){t.emitOpcode(13),o?(t.emitString(`${o.field}:${e}:${o.date.isoDate}`),t.emitPluginCall(n,1)):(t.emitString(e),t.emitPluginCall(r,1));}function Gm(t,e,o,r,n){let i=false;t.peek()?.type==="STAR"&&(t.consume(),i=true);let a=pf(t);if(i&&!a){Hm(e,o,null,r,n),t.parseExpression(chunkZDJTDFTR_cjs.a.Product,e),e.emitOpcode(22);return}Hm(e,o,a,r,n);}function zm(t,e){return {category:"Stocks",parse(o,r,n){o.consume("LPAREN");let i=o.consume(),a;if(i.type==="STRING")a=chunkUURM7P3P_cjs.a(i.value).toUpperCase();else if(i.type==="IDENT"||i.type===Me)a=i.value.toUpperCase();else throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_TICKER",`Expected a ticker symbol inside stock(...), got "${i.value}" (${i.type})`);o.consume("RPAREN"),Gm(o,n,a,t,e);}}}function Km(t,e){return {category:"Stocks",parse(o,r,n){let i=r.value.toUpperCase();Gm(o,n,i,t,e);}}}var $n="solve-stocks",oo="stock",no="stockhistorical";function $m(t={}){function e(s){return chunkGJZIJK2Q_cjs.P("STOCKS_NOT_CONFIGURED",`Stock data provider not configured. Supply ${s} via createStocksPackage({ ... }); see the StocksPackage doc comment.`)}let{resolver:o,pluginFunction:r}=oe({namespace:"stocks-current",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${$n}:${oo}`),staleTimeMs:t.staleTimeMs??6e4,refetchIntervalMs:t.refetchIntervalMs,fetchQuery:async(s,l)=>{if(!t.fetchQuote)return e("fetchQuote");let u=await t.fetchQuote(s,l);return chunkGJZIJK2Q_cjs.u(u.price,u.currency??"USD")}}),{resolver:n,pluginFunction:i}=oe({namespace:"stocks-historical",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${$n}:${no}`),staleTimeMs:t.historicalStaleTimeMs??720*60*60*1e3,fetchQuery:async(s,l)=>{let[u,c,f]=s.split(":");if(!t.fetchHistoricalQuote)return e("fetchHistoricalQuote");let T=await t.fetchHistoricalQuote(c,f,l);return u==="volume"?chunkGJZIJK2Q_cjs.n(T.volume??0):chunkGJZIJK2Q_cjs.u(T.close,T.currency??"USD")}});return {name:$n,lexerVocabulary:{keywords:{stock:"STOCK_FN"}},prefixParselets:{STOCK_FN:zm(oo,no),...t.enableBareTickerRecognition?{[Me]:Km(oo,no)}:{}},normalizerRules:t.enableBareTickerRecognition?[Fm()]:[],pluginFunctions:{[oo]:r,[no]:i},asyncResolvers:[o,n]}}var io=class{constructor(e){this.fn=e;this.category="Crypto";}parse(e,o,r){e.consume("LPAREN");let n=e.consume(),i=String(n.value??"").trim().toUpperCase();e.consume("RPAREN"),r.emitOpcode(13),r.emitString(i),r.emitPluginCall(this.fn,1);}};var Wm="solve-crypto",Wn="crypto";function Ym(t={}){function e(){return chunkGJZIJK2Q_cjs.P("CRYPTO_NOT_CONFIGURED","Crypto price provider not configured. Supply fetchPrice via createCryptoPackage({ fetchPrice }); see the CryptoPackage doc comment.")}let{resolver:o,pluginFunction:r}=oe({namespace:"crypto",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${Wm}:${Wn}`),staleTimeMs:t.staleTimeMs??6e4,refetchIntervalMs:t.refetchIntervalMs,fetchQuery:async(n,i)=>{if(!t.fetchPrice)return e();let a=await t.fetchPrice(n,i);return chunkGJZIJK2Q_cjs.u(a.price,a.currency??"USD")}});return {name:Wm,lexerVocabulary:{keywords:{crypto:"CRYPTO_FN"}},prefixParselets:{CRYPTO_FN:new io(Wn)},pluginFunctions:{[Wn]:r},asyncResolvers:[o],tokenCategories:{CRYPTO_FN:"function"}}}function jm(t){return {category:"Knowledge",parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall(t,1);}}}function Xm(t={}){let e="solve-knowledge",o="knowledge",r=chunkQQHHZPEW_cjs.F(`${e}:${o}`),{resolver:n,pluginFunction:i}=oe({namespace:"knowledge",pluginFunctionIndex:r,staleTimeMs:t.staleTimeMs??300*1e3,fetchQuery:async(a,s)=>{if(!t.answerQuery)return chunkGJZIJK2Q_cjs.P("KNOWLEDGE_NOT_CONFIGURED","Knowledge answer provider not configured. Supply answerQuery via createKnowledgePackage({ ... }); see the KnowledgePackage doc comment.");let l=await t.answerQuery(a,s);return chunkGJZIJK2Q_cjs.t(l)}});return {name:e,lexerVocabulary:{rawLinePatterns:[{pattern:/^(?:search|ask|google)\s*:\s*(.+)$/i,tokenType:"KNOWLEDGE_QUERY"},{pattern:/^(.+?)=\s*\?\s*$/,tokenType:"KNOWLEDGE_QUERY"}]},prefixParselets:{KNOWLEDGE_QUERY:jm(o)},pluginFunctions:{[o]:i},asyncResolvers:[n]}}var ao=class{constructor(){this.category="Lines";}parse(e,o,r){r.emitPluginCall("prev",0);}};var so=class{constructor(){this.category="Lines";}parse(e,o,r){let n=parseInt(o.value,10);r.emitOpcode(10),r.emitNumber(n),r.emitPluginCall("lineRef",1);}};var Et=class{constructor(e){this.isAverage=e;this.category="Lines";}parse(e,o,r){e.consume("LPAREN");let n=e.consume("LINE_REF");e.consume("COLON");let i=e.consume("LINE_REF");e.consume("RPAREN");let a=parseInt(n.value,10),s=parseInt(i.value,10);r.emitOpcode(10),r.emitNumber(a),r.emitOpcode(10),r.emitNumber(s),r.emitPluginCall(this.isAverage?"averageRange":"sumRange",2);}};var Ue=class{constructor(e){this.isAverage=e;this.category="Lines";}parse(e,o,r){r.emitPluginCall(this.isAverage?"averageAbove":"totalAbove",0);}};var ff=chunkYBQOQTVL_cjs.c("LINE_REF"),df=chunkYBQOQTVL_cjs.c("SUM_RANGE_CALL"),Ef=chunkYBQOQTVL_cjs.c("AVERAGE_RANGE_CALL");function qm(){return {name:"lines:line-ref",priority:80,startTokenTypes:["IDENT"],match(t,e){if(e>0&&t[e-1].type==="COLON"&&!(e>1&&t[e-2].type==="LINE_REF"))return null;let o=t[e];if(!o)return null;if(o.type==="IDENT"){let r=/^line(\d+)$/i.exec(o.value);if(r)return {consumed:1,replacement:[Qm(r[1],o)],ruleName:"lines:line-ref"}}if(o.type==="IDENT"&&/^line$/i.test(o.value)){let r=t[e+1];if(r&&r.type==="NUMBER"&&/^\d+$/.test(r.value))return {consumed:2,replacement:[Qm(r.value,o)],ruleName:"lines:line-ref"}}return null}}}function Qm(t,e){return new chunk6EYKVQT3_cjs.a("LINE_REF",ff,t,t,e.offset,0,e.line,e.col)}function Zm(){return {name:"lines:range-call",priority:80,shape:[{types:["IDENT"],values:["sum","total","average"]},{types:["LPAREN"]}],match(t,e){let o=t[e];if(!o||o.type!=="IDENT")return null;let r=o.value.toLowerCase();if(r!=="sum"&&r!=="total"&&r!=="average"||t[e+1]?.type!=="LPAREN")return null;let n=r==="average"?"AVERAGE_RANGE_CALL":"SUM_RANGE_CALL",i=r==="average"?Ef:df;return {consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(n,i,o.value,o.value,o.offset,0,o.line,o.col)],ruleName:"lines:range-call"}}}}function mo(t,e){return t===void 0?chunkGJZIJK2Q_cjs.P("LINE_NOT_YET_EVALUATED",`Line ${e} has not been evaluated yet (forward reference, or out of range)`):t.type===12?chunkGJZIJK2Q_cjs.P("LINE_RESULT_PENDING",`Line ${e}'s result is still resolving`):t.type===13?chunkGJZIJK2Q_cjs.P("LINE_RESULT_ERROR",`Line ${e} has an error`):null}function De(t){return t?.getLineResult?null:chunkGJZIJK2Q_cjs.P("LINE_REF_NO_DOCUMENT","Cross-line references require a real document \u2014 not available outside one (e.g. evaluateExpression()'s single-expression path)")}function Jm(t,e){let o=De(e);if(o)return o;let r=e.lineIndex-1,n=e.getLineResult(r);return mo(n,r)??n}function el(t,e){let o=De(e);if(o)return o;let r=t[0].toNumber(),n=e.getLineResult(r);return mo(n,r)??n}function tl(t,e,o,r){let n=0,i=0,a,s=false,l=t<=e?1:-1;for(let c=t;l>0?c<=e:c>=e;c+=l){let f=o.getLineResult(c),T=mo(f,c);if(T)return T;if(f.type!==0&&f.type!==6)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_NON_NUMERIC",`Line ${c} is not a plain number or unit value \u2014 cannot include it in a sum/total/average range`);if(f.type===6){if(s=true,a===void 0)a=f.unit;else if(f.unit!==a)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_MIXED_UNITS",`Line ${c}'s unit (${f.unit}) doesn't match the range's first unit (${a}) \u2014 aggregating mixed units would silently misrepresent the result`)}n+=f.toNumber(),i++;}let u=r?n/i:n;return s?chunkGJZIJK2Q_cjs.u(u,a):chunkGJZIJK2Q_cjs.n(u)}function rl(t,e){let o=De(e);return o||tl(t[0].toNumber(),t[1].toNumber(),e,false)}function ol(t,e){let o=De(e);return o||tl(t[0].toNumber(),t[1].toNumber(),e,true)}function nl(t,e){let o=t.isLineBoundary;if(!o)return chunkGJZIJK2Q_cjs.P("LINE_REF_NO_DOCUMENT",'"above" aggregation requires a real document');let r=0,n=0,i,a=false;for(let l=t.lineIndex-1;l>=1&&!o(l);l--){let u=t.getLineResult(l),c=mo(u,l);if(c)return c;if(u.type!==0&&u.type!==6)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_NON_NUMERIC",`Line ${l} is not a plain number or unit value \u2014 cannot include it in "above" aggregation`);if(u.type===6){if(a=true,i===void 0)i=u.unit;else if(u.unit!==i)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_MIXED_UNITS",`Line ${l}'s unit (${u.unit}) doesn't match the range's unit (${i})`)}r+=u.toNumber(),n++;}if(n===0)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_EMPTY","No lines above to aggregate (hit the top of the document, a blank line, or a heading immediately)");let s=e?r/n:r;return a?chunkGJZIJK2Q_cjs.u(s,i):chunkGJZIJK2Q_cjs.n(s)}function il(t,e){let o=De(e);return o||nl(e,false)}function al(t,e){let o=De(e);return o||nl(e,true)}var Yn={name:"solve-lines",lexerVocabulary:{keywords:{prev:"PREV"}},phrases:{"total above":"TOTAL_ABOVE","sum above":"SUM_ABOVE","average above":"AVERAGE_ABOVE"},normalizerRules:[qm(),Zm()],prefixParselets:{PREV:new ao,LINE_REF:new so,SUM_RANGE_CALL:new Et(false),AVERAGE_RANGE_CALL:new Et(true),TOTAL_ABOVE:new Ue(false),SUM_ABOVE:new Ue(false),AVERAGE_ABOVE:new Ue(true)},pluginFunctions:{prev:Jm,lineRef:el,sumRange:rl,averageRange:ol,totalAbove:il,averageAbove:al}};var V=class{constructor(e){this.pluginFnName=e;this.category="Tables";}parse(e,o,r){let n=e.peek();if(!n||n.type!=="STRING")throw chunkGXO7TSXQ_cjs.c.parsing("TABLE_COLUMN_NAME_EXPECTED",`Expected a quoted column name after "... of column" but got ${n?`"${n.value}"`:"end of input"}`);let i=e.consume("STRING");for(;;){let a=e.peek();if(!a)break;if(a.type==="IN"){e.consume();continue}if(a.type==="IDENT"&&Tf.has(a.value.toLowerCase())){e.consume();continue}break}r.emitOpcode(13),r.emitString(i.value),r.emitPluginCall(this.pluginFnName,1);}},Tf=new Set(["the","table","above"]);function sl(t){return t.trimStart().startsWith("|")}function Nf(t){let e=t.trim();return e.length===0||!e.includes("-")||!e.includes("|")?false:/^[|\s:-]+$/.test(e)}function ml(t){let e=t.trim();e.startsWith("|")&&(e=e.slice(1)),e.endsWith("|")&&!e.endsWith("\\|")&&(e=e.slice(0,-1));let o=[],r="";for(let n=0;n<e.length;n++){let i=e[n];if(i==="\\"&&n+1<e.length&&e[n+1]==="|"){r+="|",n++;continue}if(i==="|"){o.push(r.trim()),r="";continue}r+=i;}return o.push(r.trim()),o}function yf(t){if(t===void 0)return null;let e=t.trim();if(e.length===0)return null;let o=e.replace(/,/g,"");if(!/^[+-]?(\d+(\.\d+)?|\.\d+)$/.test(o))return null;let r=Number.parseFloat(o);return Number.isFinite(r)?r:null}function ll(t,e){let o=-1;for(let s=e-1;s>=1;s--){let l=t(s);if(l===void 0)break;if(sl(l)){o=s;break}}if(o===-1)return null;let r=o;for(;r-1>=1;){let s=t(r-1);if(s===void 0||!sl(s))break;r--;}let n=-1;for(let s=r;s<=o;s++)if(Nf(t(s))){n=s;break}if(n===-1||n===r)return null;let i=ml(t(n-1)),a=[];for(let s=n+1;s<=o;s++)a.push(ml(t(s)));return {header:i,rows:a}}function ul(t,e){let o=e.trim().toLowerCase();for(let r=0;r<t.length;r++)if(t[r].trim().toLowerCase()===o)return r;return -1}function cl(t,e){let o=[];for(let r of t.rows){let n=yf(r[e]);n!==null&&o.push(n);}return o}var lo={TABLE_NO_DOCUMENT:"TABLE_NO_DOCUMENT",TABLE_NOT_FOUND:"TABLE_NOT_FOUND",TABLE_COLUMN_NOT_FOUND:"TABLE_COLUMN_NOT_FOUND",TABLE_COLUMN_NO_NUMERIC_CELLS:"TABLE_COLUMN_NO_NUMERIC_CELLS"};function uo(t,e){let o=t.length;if(o===0)return 0;let r=e?o-1:o;if(r<=0)return 0;let n=t.reduce((i,a)=>i+a,0)/o;return t.reduce((i,a)=>i+(a-n)*(a-n),0)/r}function gf(t,e){switch(t){case "sum":return e.reduce((o,r)=>o+r,0);case "average":return e.reduce((o,r)=>o+r,0)/e.length;case "min":return Math.min(...e);case "max":return Math.max(...e);case "count":return e.length;case "median":{let o=[...e].sort((n,i)=>n-i),r=Math.floor(o.length/2);return o.length%2===0?(o[r-1]+o[r])/2:o[r]}case "stdev":return Math.sqrt(uo(e,false));case "sampleStdev":return Math.sqrt(uo(e,true));case "variance":return uo(e,false);case "sampleVariance":return uo(e,true);case "spread":return Math.max(...e)-Math.min(...e);case "mode":{let o=new Map,r=e[0],n=0;for(let i of e){let a=(o.get(i)??0)+1;o.set(i,a),a>n&&(n=a,r=i);}return r}}}function $(t,e,o){let r=o?.getLineText;if(!r||o.lineIndex<1)return chunkGJZIJK2Q_cjs.P(lo.TABLE_NO_DOCUMENT,"Reading a table column needs a real document, which the single-expression path (evaluateExpression) does not have");let n=ll(r,o.lineIndex);if(!n)return chunkGJZIJK2Q_cjs.P(lo.TABLE_NOT_FOUND,'No markdown table found above this line (a table row starts with "|", and needs a "|---|" separator under its header)');let i=ul(n.header,e);if(i===-1){let s=n.header.map(l=>`"${l}"`).join(", ");return chunkGJZIJK2Q_cjs.P(lo.TABLE_COLUMN_NOT_FOUND,`The table above has no column named "${e}". Its columns are: ${s}`)}let a=cl(n,i);return t==="count"?chunkGJZIJK2Q_cjs.n(a.length):a.length===0?chunkGJZIJK2Q_cjs.P(lo.TABLE_COLUMN_NO_NUMERIC_CELLS,`Column "${e}" has no plain-number cells to aggregate (currency and unit cells are not read yet)`):chunkGJZIJK2Q_cjs.n(gf(t,a))}function W(t){let e=t[0];return e&&e.type===3&&typeof e.value=="string"?e.value:String(e?.value??"")}function pl(t,e){return $("sum",W(t),e)}function fl(t,e){return $("average",W(t),e)}function dl(t,e){return $("min",W(t),e)}function El(t,e){return $("max",W(t),e)}function Tl(t,e){return $("count",W(t),e)}function Nl(t,e){return $("median",W(t),e)}function yl(t,e){return $("stdev",W(t),e)}function gl(t,e){return $("sampleStdev",W(t),e)}function Pl(t,e){return $("variance",W(t),e)}function _l(t,e){return $("sampleVariance",W(t),e)}function xl(t,e){return $("spread",W(t),e)}function Al(t,e){return $("mode",W(t),e)}var jn={name:"solve-tables",phrases:{"sum of column":"TABLE_COLUMN_SUM","total of column":"TABLE_COLUMN_SUM","average of column":"TABLE_COLUMN_AVERAGE","mean of column":"TABLE_COLUMN_AVERAGE","min of column":"TABLE_COLUMN_MIN","minimum of column":"TABLE_COLUMN_MIN","max of column":"TABLE_COLUMN_MAX","maximum of column":"TABLE_COLUMN_MAX","count of column":"TABLE_COLUMN_COUNT","median of column":"TABLE_COLUMN_MEDIAN","standard deviation of column":"TABLE_COLUMN_STDEV","stdev of column":"TABLE_COLUMN_STDEV","sample standard deviation of column":"TABLE_COLUMN_SAMPLE_STDEV","variance of column":"TABLE_COLUMN_VARIANCE","sample variance of column":"TABLE_COLUMN_SAMPLE_VARIANCE","spread of column":"TABLE_COLUMN_SPREAD","mode of column":"TABLE_COLUMN_MODE"},prefixParselets:{TABLE_COLUMN_SUM:new V("TABLE_COLUMN_SUM"),TABLE_COLUMN_AVERAGE:new V("TABLE_COLUMN_AVERAGE"),TABLE_COLUMN_MIN:new V("TABLE_COLUMN_MIN"),TABLE_COLUMN_MAX:new V("TABLE_COLUMN_MAX"),TABLE_COLUMN_COUNT:new V("TABLE_COLUMN_COUNT"),TABLE_COLUMN_MEDIAN:new V("TABLE_COLUMN_MEDIAN"),TABLE_COLUMN_STDEV:new V("TABLE_COLUMN_STDEV"),TABLE_COLUMN_SAMPLE_STDEV:new V("TABLE_COLUMN_SAMPLE_STDEV"),TABLE_COLUMN_VARIANCE:new V("TABLE_COLUMN_VARIANCE"),TABLE_COLUMN_SAMPLE_VARIANCE:new V("TABLE_COLUMN_SAMPLE_VARIANCE"),TABLE_COLUMN_SPREAD:new V("TABLE_COLUMN_SPREAD"),TABLE_COLUMN_MODE:new V("TABLE_COLUMN_MODE")},pluginFunctions:{TABLE_COLUMN_SUM:pl,TABLE_COLUMN_AVERAGE:fl,TABLE_COLUMN_MIN:dl,TABLE_COLUMN_MAX:El,TABLE_COLUMN_COUNT:Tl,TABLE_COLUMN_MEDIAN:Nl,TABLE_COLUMN_STDEV:yl,TABLE_COLUMN_SAMPLE_STDEV:gl,TABLE_COLUMN_VARIANCE:Pl,TABLE_COLUMN_SAMPLE_VARIANCE:_l,TABLE_COLUMN_SPREAD:xl,TABLE_COLUMN_MODE:Al}};var be=class{constructor(e){this.pluginFnName=e;this.category="Tags";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall(this.pluginFnName,1);}};function co(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}var Rl={TOTAL_OF:"TAG_SUM",COUNT_OF:"TAG_COUNT",AVERAGE_OF:"TAG_AVERAGE"},Pf=new Set(["total","sum","count","average"]);function Ol(t=80){return {name:"tags:aggregate",priority:t,shape:[{types:["TOTAL_OF","COUNT_OF","AVERAGE_OF","IDENT"]}],match(e,o){let r=e[o];if(r===void 0)return null;let n=Rl[r.type];if(n!==void 0){let i=e[o+1];return i?.type!=="TAG"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b(n,i.value??"",[r,i])],ruleName:"tags:aggregate"}}if(r.type==="IDENT"&&co(r)==="sum"){let i=e[o+1],a=e[o+2];return co(i)!=="of"||a?.type!=="TAG"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("TAG_SUM",a.value??"",[r,i,a])],ruleName:"tags:aggregate"}}return null}}}function Cl(t=40){return {name:"tags:strip",priority:t,shape:[{types:["TAG"]}],match(e,o){if(e[o]?.type!=="TAG")return null;let r=e[o-1];return r!==void 0&&(Rl[r.type]!==void 0||co(r)==="of"&&Pf.has(co(e[o-2])))?null:{consumed:1,replacement:[],ruleName:"tags:strip"}}}}function _f(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Il(t,e){if(e==="")return false;let r=new RegExp(`(?:^|[^0-9A-Za-z_])#${_f(e)}(?![0-9A-Za-z_-])`,"i").exec(t);if(r===null)return false;let n=r.index+r[0].indexOf("#");return t.slice(0,n).trim().length>0}function xf(t,e){return t===void 0?chunkGJZIJK2Q_cjs.P("LINE_NOT_YET_EVALUATED",`Line ${e} has not been evaluated yet`):t.type===12?chunkGJZIJK2Q_cjs.P("LINE_RESULT_PENDING",`Line ${e}'s result is still resolving`):t.type===13?chunkGJZIJK2Q_cjs.P("LINE_RESULT_ERROR",`Line ${e} has an error`):null}function Xn(t){return !t?.getLineResult||!t.getLineText?chunkGJZIJK2Q_cjs.P("TAG_NO_DOCUMENT","Category tag sums require a real document, not available outside one (e.g. evaluateExpression()'s single-expression path)"):null}function Qn(t,e,o){let r=t.getLineText,n=t.getLineResult,i=t.isLineBoundary,a=e.toLowerCase(),s=0,l=0,u,c=false;for(let T=1;;T++){let N=r(T);if(N===void 0)break;if(T===t.lineIndex||i&&i(T)||!Il(N,a))continue;let E=n(T),P=xf(E,T);if(P)return P;if(o!=="count"){if(E.type!==0&&E.type!==6)return chunkGJZIJK2Q_cjs.P("TAG_NON_NUMERIC",`Line ${T}, tagged #${e}, is not a plain number or unit value.`);if(E.type===6){if(c=true,u===void 0)u=E.unit;else if(E.unit!==u)return chunkGJZIJK2Q_cjs.P("TAG_MIXED_UNITS",`Line ${T}'s unit (${E.unit}) doesn't match #${e}'s first unit (${u}), aggregating mixed units would misrepresent the result.`)}s+=E.toNumber();}l++;}if(o==="count")return chunkGJZIJK2Q_cjs.n(l);if(l===0)return chunkGJZIJK2Q_cjs.P("TAG_EMPTY",`No lines are tagged #${e}.`);let f=o==="average"?s/l:s;return c?chunkGJZIJK2Q_cjs.u(f,u):chunkGJZIJK2Q_cjs.n(f)}function hl(t,e){let o=Xn(e);return o||Qn(e,String(t[0].value),"sum")}function Sl(t,e){let o=Xn(e);return o||Qn(e,String(t[0].value),"average")}function Ll(t,e){let o=Xn(e);return o||Qn(e,String(t[0].value),"count")}var qn={name:"solve-tags",normalizerRules:[Ol(),Cl()],prefixParselets:{TAG_SUM:new be("sum"),TAG_AVERAGE:new be("average"),TAG_COUNT:new be("count")},pluginFunctions:{sum:hl,average:Sl,count:Ll}};var Tt=class{constructor(e){this.fn=e;this.category="Payroll";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall(this.fn,1);}},Nt=class{constructor(e){this.fn=e;this.category="Payroll";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall(this.fn,1);}};function Af(t,e){if(t<=e.personalAllowanceTaperFrom)return e.personalAllowance;let o=(t-e.personalAllowanceTaperFrom)/2;return Math.max(0,e.personalAllowance-o)}function Rf(t,e){let o=Math.max(0,t-Af(t,e)),r=Math.min(o,e.basicRateLimit),n=Math.min(Math.max(0,o-e.basicRateLimit),e.higherRateLimit-e.basicRateLimit),i=Math.max(0,o-e.higherRateLimit);return r*e.basicRate+n*e.higherRate+i*e.additionalRate}function Of(t,e){if(t<=e.niPrimaryThreshold)return 0;let o=Math.min(t,e.niUpperEarningsLimit)-e.niPrimaryThreshold,r=Math.max(0,t-e.niUpperEarningsLimit);return o*e.niMainRate+r*e.niUpperRate}function Zn(t,e){return t-Rf(t,e)-Of(t,e)}var Cf=1920;function vl(t){return t/Cf}var Jn={personalAllowance:12570,personalAllowanceTaperFrom:1e5,basicRateLimit:37700,higherRateLimit:125140,basicRate:.2,higherRate:.4,additionalRate:.45,niPrimaryThreshold:12570,niUpperEarningsLimit:50270,niMainRate:.08,niUpperRate:.02};var ei=Jn;function ti(t,e){let o=e(t.toNumber());return t.type===6?chunkGJZIJK2Q_cjs.u(o,t.unit):chunkGJZIJK2Q_cjs.n(o)}var ri={name:"solve-payroll",phrases:{"take home on":"TAKE_HOME_ON","hourly for":"HOURLY_FOR","after tax":"AFTER_TAX","salary after tax":"AFTER_TAX","per month after tax":"AFTER_TAX_MONTHLY","monthly after tax":"AFTER_TAX_MONTHLY","salary per month after tax":"AFTER_TAX_MONTHLY"},prefixParselets:{TAKE_HOME_ON:new Tt("payrollTakeHome"),HOURLY_FOR:new Tt("payrollHourly")},infixParselets:{AFTER_TAX:new Nt("payrollTakeHome"),AFTER_TAX_MONTHLY:new Nt("payrollTakeHomeMonthly")},pluginFunctions:{payrollTakeHome:t=>ti(t[0],e=>Zn(e,ei)),payrollTakeHomeMonthly:t=>ti(t[0],e=>Zn(e,ei)/12),payrollHourly:t=>ti(t[0],vl)},tokenCategories:{TAKE_HOME_ON:"function",HOURLY_FOR:"function",AFTER_TAX:"operator",AFTER_TAX_MONTHLY:"operator"}};function If(t){return {category:"Shopping",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitPluginCall(t,2);}}}function hf(t){let e=t[0],o=t[1],r=e.toNumber(),n=o.toNumber();if(e.type===6||o.type===6){if(e.type!==6||o.type!==6||e.unit===void 0||o.unit===void 0)return chunkGJZIJK2Q_cjs.P("VS_INCOMPARABLE","vs: compare two amounts of the same kind");if(e.unit!==o.unit){if(!chunkZKFCKAIX_cjs.d(o.unit,e.unit))return chunkGJZIJK2Q_cjs.P("VS_INCOMPARABLE",`vs: ${e.unit} and ${o.unit} are not the same kind of thing`);n=chunkZKFCKAIX_cjs.e(n,o.unit,e.unit);}}if(Math.abs(r-n)<=Math.max(Math.abs(r),Math.abs(n))*1e-9)return chunkGJZIJK2Q_cjs.t("the same");let i=r<n,a=Math.min(r,n),s=Math.max(r,n),l=Math.round((s-a)/s*100);return chunkGJZIJK2Q_cjs.t(`the ${i?"first":"second"} is cheaper, ${l}% less`)}var oi={name:"solve-shopping",lexerVocabulary:{keywords:{vs:"VS_COMPARE",versus:"VS_COMPARE"}},infixParselets:{VS_COMPARE:If("shoppingCompare")},pluginFunctions:{shoppingCompare:hf},tokenCategories:{VS_COMPARE:"operator"}};var po=class{constructor(){this.category="operator";this.bindingPower=chunkZDJTDFTR_cjs.a.Uncertainty;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(28);}};function Bl(t=90){return {name:"uncertainty:ascii-plus-minus",priority:t,shape:[{types:["PLUS"]},{types:["SLASH"]}],match(e,o){let r=e[o];if(r?.type!=="PLUS")return null;let n=e[o+1];if(n?.type!=="SLASH")return null;let i=e[o+2];return i?.type!=="MINUS"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("PLUS_MINUS","\xB1",[r,n,i])],ruleName:"uncertainty:ascii-plus-minus"}}}}var ni={name:"solve-uncertainty",infixParselets:{PLUS_MINUS:new po},normalizerRules:[Bl()]};var Ml=1e-9,Ul=1e9,Sf=100,Lf=1e-9,vf=1e-9,wf=1e-12,kf=1e-9,fo="goalseek";function Dl(t,e){let o=e?.evaluateLineWithBinding,r=e?.getLineReads;if(!o||!r)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NO_DOCUMENT","Goal seek only works inside a document, since it re-runs another line. The single-expression entry point has no document to solve against.");let n=t[0].toNumber(),i=typeof t[1].value=="string"?t[1].value:String(t[1].value),a=t[2];if(a.type!==0&&a.type!==6)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC",`Goal seek's target must be a number, as in "solve line ${n} for ${i} = 900".`);let s=a.toNumber();if(!Number.isFinite(s))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC","Goal seek's target is not a finite number.");let l=r(n);if(l===void 0)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_LINE_NOT_READY",`Line ${n} has no evaluated expression to solve (forward reference, out of range, or not an expression).`);if(!l.includes(i))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_VARIABLE_NOT_USED",`Line ${n} does not use ${i}, so changing ${i} cannot move its result toward ${s}.`);let u=o(n,i,chunkGJZIJK2Q_cjs.K(chunkFDKTESBC_cjs.q(i)),true);if(u.type===9){let f=Bf(u.value,s,i);if(f!==null)return chunkGJZIJK2Q_cjs.n(f)}let c=e.goalSeekMaxIterations??Sf;return Mf(o,n,i,s,c)}function Bf(t,e,o){let r=chunkFDKTESBC_cjs.p(chunkFDKTESBC_cjs.d(e)),n;try{n=chunkQQHHZPEW_cjs.d(t,r,o);}catch{return null}if(n.kind!=="roots")return null;let i=[];for(let l of n.exact){let u=chunkFDKTESBC_cjs.Q(l);if(u.kind==="const"){let c=chunkFDKTESBC_cjs.e(u.value);Number.isFinite(c)&&i.push(c);}}for(let l of n.approximate)Math.abs(l.im)<=kf&&Number.isFinite(l.re)&&i.push(l.re);if(i.length===0)return null;let a=i.filter(l=>l>=Ml&&l<=Ul),s=a.length>0?a:i;return s.sort((l,u)=>Math.abs(l)-Math.abs(u)),s[0]}function Mf(t,e,o,r,n){let i=N=>{let E=t(e,o,chunkGJZIJK2Q_cjs.n(N),false);if(E.type===13)return {error:E};if(E.type!==0&&E.type!==6)return {error:chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC",`Line ${e} did not produce a number when ${o} was set to ${N}, so goal seek cannot compare it to the target.`)};let P=E.toNumber();return Number.isFinite(P)?{value:P}:{error:chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NON_FINITE",`Line ${e}'s result is not finite when ${o} is ${N}.`)}},a=Ml,s=Ul,l=i(a);if("error"in l)return l.error;let u=i(s);if("error"in u)return u.error;let c=Math.max(Lf,Math.abs(r)*vf),f=l.value-r,T=u.value-r;if(Math.abs(f)<=c)return chunkGJZIJK2Q_cjs.n(a);if(Math.abs(T)<=c)return chunkGJZIJK2Q_cjs.n(s);if(Math.sign(f)===Math.sign(T))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NO_SOLUTION",`No value of ${o} between ${a} and ${s} makes line ${e} equal ${r}: across that whole range its result stays on one side of the target.`);for(let N=0;N<n;N++){let E=(a+s)/2,P=i(E);if("error"in P)return P.error;let R=P.value-r;if(Math.abs(R)<=c)return chunkGJZIJK2Q_cjs.n(E);if(s-a<=wf)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_DID_NOT_CONVERGE",`Goal seek narrowed ${o} to a single point near ${E} without line ${e} reaching ${r}: the relationship jumps across the target rather than passing through it.`);Math.sign(R)===Math.sign(f)?(a=E,f=R):s=E;}return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_DID_NOT_CONVERGE",`Goal seek did not bring line ${e} within tolerance of ${r} by varying ${o} in ${n} steps.`)}var Eo=class{constructor(){this.category="GoalSeek";}parse(e,o,r){let n=e.peek();if(!n||n.type!=="LINE_REF")throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_SYNTAX",'Goal seek reads "solve line N for <var> = <target>", for example "solve line 4 for rate = 900".',{found:n?.type??"end of input"});e.consume();let i=parseInt(n.value,10),a=e.peek();if(!(!!a&&(a.type==="FOR_DURATION"||a.type==="IDENT"&&a.value.toLowerCase()==="for")))throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_SYNTAX",'Goal seek reads "solve line N for <var> = <target>". Expected "for" after the line reference.',{found:a?.type??"end of input"});e.consume();let l=e.peek();if(!l||l.type!=="IDENT"&&l.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_REQUIRES_VARIABLE_NAME",'Goal seek needs the name of the variable to vary here, as in "solve line 4 for rate = 900".',{found:l?.type??"end of input"});e.consume(),e.consume("EQUALS"),r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(13),r.emitString(l.value),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall(fo,3);}};var Uf=chunkYBQOQTVL_cjs.c("GOAL_SEEK");function bl(t=75){return {name:"goalseek:solve-line",priority:t,shape:[{types:["IDENT"],values:["solve"]},{types:["LINE_REF"]}],match(e,o){if(o>0&&e[o-1].type==="COLON")return null;let r=e[o];return !r||r.type!=="IDENT"||r.value.toLowerCase()!=="solve"||e[o+1]?.type!=="LINE_REF"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("GOAL_SEEK",Uf,r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"goalseek:solve-line"}}}}var ii={name:"solve-goalseek",normalizerRules:[bl()],prefixParselets:{GOAL_SEEK:new Eo},pluginFunctions:{[fo]:Dl}};var To=class{constructor(){this.category="Colour";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("colour",1);}};var Ne={COLOUR_INVALID:"COLOUR_INVALID",COLOUR_EXPECTED_COLOUR:"COLOUR_EXPECTED_COLOUR",COLOUR_BAD_ARGUMENTS:"COLOUR_BAD_ARGUMENTS"};function M(t){return t&&t.type===14?t.value:null}function D(t){if(!t)return 0;let e=t.toNumber();return t.type===5?e:e>1?e/100:e}function J(t,e){return chunkGJZIJK2Q_cjs.P(Ne.COLOUR_BAD_ARGUMENTS,`${t}(...) expects ${e}`)}function Q(t){return chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,`${t}(...) expects a colour as its first argument`)}function Vl(t){let e=t[0];if(!e||e.type!==3||typeof e.value!="string")return J("color",'a string, e.g. color("#ff0000") or color("red")');let o=chunk5TVI2UPZ_cjs.c(e.value);return o?chunkGJZIJK2Q_cjs.G(o):chunkGJZIJK2Q_cjs.P(Ne.COLOUR_INVALID,`"${e.value}" is not a hex colour (#rgb, #rgba, #rrggbb, #rrggbbaa) or a CSS colour name`)}function Df(t){return t.length!==3?J("rgb","three numbers: rgb(red, green, blue)"):chunkGJZIJK2Q_cjs.G({r:chunk5TVI2UPZ_cjs.a(t[0].toNumber()),g:chunk5TVI2UPZ_cjs.a(t[1].toNumber()),b:chunk5TVI2UPZ_cjs.a(t[2].toNumber()),a:1,format:"rgb"})}function bf(t){return t.length!==4?J("rgba","four numbers: rgba(red, green, blue, alpha)"):chunkGJZIJK2Q_cjs.G({r:chunk5TVI2UPZ_cjs.a(t[0].toNumber()),g:chunk5TVI2UPZ_cjs.a(t[1].toNumber()),b:chunk5TVI2UPZ_cjs.a(t[2].toNumber()),a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"rgba"})}function Vf(t){if(t.length!==3)return J("hsl","three values: hsl(hue, saturation%, lightness%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.e(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hsl"})}function Ff(t){if(t.length!==4)return J("hsla","four values: hsla(hue, saturation%, lightness%, alpha)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.e(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"hsla"})}function ye(t,e){return o=>{let r=M(o[0]);return r?o.length<2?J(t,`a colour and an amount, e.g. ${t}(#3366cc, 20%)`):chunkGJZIJK2Q_cjs.G(e(r,D(o[1]))):Q(t)}}var Hf=ye("lighten",chunk5TVI2UPZ_cjs.j),Gf=ye("darken",chunk5TVI2UPZ_cjs.k),zf=ye("saturate",chunk5TVI2UPZ_cjs.l),Fl=ye("desaturate",chunk5TVI2UPZ_cjs.m);function ai(t){let e=M(t[0]);return e?t.length<2?J("rotate","a colour and a hue angle in degrees, e.g. rotate(#ff0000, 90)"):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.n(e,t[1].toNumber())):Q("rotate")}function Kf(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.o(e)):Q("complement")}function Hl(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.p(e)):Q("grayscale")}function Gl(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.q(e,t.length>1?D(t[1]):1)):Q("invert")}function $f(t){let e=M(t[0]),o=M(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"mix(...) expects two colours to blend"):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.r(e,o,t.length>2?D(t[2]):.5))}function si(t){let e=M(t[0]);return e?t.length<2?chunkGJZIJK2Q_cjs.n(e.a):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.s(e,D(t[1]))):Q("alpha")}function Wf(t){let e=M(t[0]),o=M(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"contrast(...) expects two colours"):chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.i(e,o))}function Yf(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.h(e)):Q("luminance")}function Ve(t,e){return o=>{let r=M(o[0]);return r?chunkGJZIJK2Q_cjs.n(e(r)):Q(t)}}var jf=Ve("red",t=>t.r),Xf=Ve("green",t=>t.g),Qf=Ve("blue",t=>t.b),qf=Ve("hue",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).h),Zf=Ve("saturation",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).s*100),Jf=Ve("lightness",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).l*100);function zl(t){if(t.length!==3)return J("hsv","three values: hsv(hue, saturation%, value%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.t(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hex"})}function ed(t){if(t.length!==4)return J("hsva","four values: hsva(hue, saturation%, value%, alpha)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.t(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"hex"})}function td(t){if(t.length!==3)return J("hwb","three values: hwb(hue, whiteness%, blackness%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.u(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hex"})}var rd=ye("tint",chunk5TVI2UPZ_cjs.v),od=ye("shade",chunk5TVI2UPZ_cjs.w),nd=ye("tone",chunk5TVI2UPZ_cjs.x);function id(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.y(e)):Q("isdark")}function ad(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.L(!chunk5TVI2UPZ_cjs.y(e)):Q("islight")}function mi(t){let e=M(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.z(e)):Q("readable")}function sd(t){if(!t)return chunk5TVI2UPZ_cjs.A.aa;if(t.type===0)return t.toNumber();if(t.type===3){let e=t.value.trim().toLowerCase();if(e==="aaa")return chunk5TVI2UPZ_cjs.A.aaa;if(e==="aa large"||e==="aa-large"||e==="large")return chunk5TVI2UPZ_cjs.A.aaLarge;if(e==="aaa large"||e==="aaa-large")return chunk5TVI2UPZ_cjs.A.aaaLarge}return chunk5TVI2UPZ_cjs.A.aa}function md(t){let e=M(t[0]),o=M(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"iscontrastcompliant(...) expects two colours"):chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.i(e,o)>=sd(t[2]))}function Kl(t){let e=M(t[0]),o=M(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"wcaglevel(...) expects two colours"):chunkGJZIJK2Q_cjs.t(chunk5TVI2UPZ_cjs.B(e,o))}var ge={color:Vl,colour:Vl,rgb:Df,rgba:bf,hsl:Vf,hsla:Ff,lighten:Hf,darken:Gf,saturate:zf,desaturate:Fl,desat:Fl,rotate:ai,spin:ai,adjusthue:ai,complement:Kf,grayscale:Hl,greyscale:Hl,invert:Gl,mix:$f,alpha:si,opacity:si,fade:si,contrast:Wf,luminance:Yf,red:jf,green:Xf,blue:Qf,hue:qf,saturation:Zf,lightness:Jf,hsv:zl,hsb:zl,hsva:ed,hwb:td,tint:rd,shade:od,tone:nd,negate:Gl,isdark:id,islight:ad,readable:mi,contrastcolor:mi,contrastcolour:mi,iscontrastcompliant:md,wcaglevel:Kl,wcag:Kl};var No=class{constructor(){this.category="Colour";}parse(e,o,r){let n=o.value.toLowerCase();if(ge[n]===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_COLOUR_FUNCTION",`Unknown colour function: ${n}`,{functionName:n});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var $l=new Set(Object.keys(ge));function Wl(t=80){return {name:"colour:call",priority:t,shape:[{types:["IDENT"],values:[...$l]},{types:["LPAREN"]}],match(e,o){let r=e[o];if(!r||r.type!=="IDENT")return null;let n=r.value.toLowerCase();return !$l.has(n)||e[o+1]?.type!=="LPAREN"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("COLOUR_CALL",chunkYBQOQTVL_cjs.c("COLOUR_CALL"),r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"colour:call"}}}}var yo=t=>e=>{if(e.type!==14)return e;let o=e.value;return chunkGJZIJK2Q_cjs.G({r:o.r,g:o.g,b:o.b,a:o.a,format:t})},ld=Object.keys(ge).map(t=>({label:t,category:"function",detail:"colour"})),li={name:"solve-colour",prefixParselets:{HEX_COLOUR:new To,COLOUR_CALL:new No},normalizerRules:[Wl()],pluginFunctions:ge,asConverters:{rgb:yo("rgb"),rgba:yo("rgba"),hsl:yo("hsl"),hsla:yo("hsla")},completionItems:ld};var ui=32;function ud(t){if(t.hasSymbolic||t.rows!==1&&t.cols!==1)return null;let e=[];for(let o of t.data){if(typeof o!="number"||!Number.isFinite(o))return null;e.push(o);}return e}function cd(t){let e=t.max-t.min+1,o=Math.min(e,ui),r=[];for(let n=0;n<o;n++)r.push(t.min+Math.round(n*(e-1)/(o-1)));return r}function pd(t,e){if(t.length<=e)return [...t];let o=[];for(let r=0;r<e;r++)o.push(t[Math.round(r*(t.length-1)/(e-1))]);return o}function Yl(t){let e=null;if(t.type===7)e=ud(t.value);else if(t.type===8){let a=t.value;e=a.max-a.min+1>=2?cd(a):null;}if(!e||e.length<2)return null;let o=pd(e,ui),r=Math.min(...e),n=Math.max(...e),i=e.length<=ui?`[${e.join(", ")}]`:`sparkline of ${e.length} values`;return {kind:"sparkline",points:o.map((a,s)=>[s,a]),label:i,domain:[0,o.length-1],range:[r,n]}}var go=class{constructor(){this.category="Plot";}parse(e,o,r){let n=fd(e),i=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,i),e.setBuilder(r);let a=i.build();if(a.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("PLOT_EXPR_MUST_BE_SYNCHRONOUS","a plot expression must be synchronous (no weather, stocks or currency calls).");e.consume("FROM"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("TO"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r);let s=r.emitAnonymousBody(["x"],a);r.emitOpcode(160),r.emitIndex(s),r.emitString(n);}};function fd(t){let e=[];for(let n=0;;n++){let i=t.peekAt(n);if(!i||i.type==="FROM")break;e.push(i);}if(e.length===0)return "";let o=e[0].offset,r="";for(let n of e){let i=n.offset-o;for(;r.length<i;)r+=" ";r+=n.text??n.value??"";}return r.trim()}var Xl="PLOT",dd=chunkYBQOQTVL_cjs.c(Xl),jl=new Set(["NUMBER","IDENT","FUNC","UNIT","LPAREN","PI","E"]);function Ql(t=80){let e="plot:plot-clause";return {name:e,priority:t,shape:[{types:["IDENT"],values:["plot"]},{types:[...jl]}],match(o,r){let n=o[r];if(!n||n.type!=="IDENT"||(n.value??"").toLowerCase()!=="plot"||o[r-1]?.type==="COLON")return null;let i=o[r+1];return !i||!jl.has(i.type)?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(Xl,dd,n.value,n.value,n.offset,0,n.line,n.col)],ruleName:e}}}}var ci={name:"solve-chart",asConverters:{sparkline:t=>{let e=Yl(t);return e?chunkGJZIJK2Q_cjs.I(e):chunkGJZIJK2Q_cjs.P("SPARKLINE_NOT_A_SERIES",'"as sparkline" expects a numeric vector or a range, with at least two values')}},prefixParselets:{PLOT:new go},normalizerRules:[Ql()],tokenCategories:{PLOT:"keyword"}};var yt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function pi(t){let e=new TextEncoder().encode(t),o="";for(let r=0;r<e.length;r+=3){let n=e[r],i=r+1<e.length?e[r+1]:0,a=r+2<e.length?e[r+2]:0;o+=yt[n>>2],o+=yt[(n&3)<<4|i>>4],o+=r+1<e.length?yt[(i&15)<<2|a>>6]:"=",o+=r+2<e.length?yt[a&63]:"=";}return o}function fi(t){let e=t.replace(/\s+/g,"");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e))return null;let o=e.replace(/=+$/,""),r=[],n=0,i=0;for(let a of o){let s=yt.indexOf(a);if(s<0)return null;i=i<<6|s,n+=6,n>=8&&(n-=8,r.push(i>>n&255));}try{return new TextDecoder("utf-8",{fatal:!0}).decode(new Uint8Array(r))}catch{return null}}function ql(t){return encodeURIComponent(t)}function Zl(t){try{return decodeURIComponent(t)}catch{return null}}function Jl(t){return Array.from(new TextEncoder().encode(t)).map(e=>e.toString(16).padStart(2,"0")).join(" ")}function di(t){let e=t.trim().split(/[\s,]+/).filter(r=>r.length>0),o=[];for(let r of e){if(!/^[0-9a-fA-F]{1,2}$/.test(r))return null;o.push(parseInt(r,16));}try{return new TextDecoder("utf-8",{fatal:!0}).decode(new Uint8Array(o))}catch{return null}}function Ed(t){let e=t.replace(/-/g,"+").replace(/_/g,"/"),o=e.length%4;return o===0?e:e+"=".repeat(4-o)}function Ei(t){let e=t.trim().split(".");if(e.length<2||e[1]==="")return null;let o=fi(Ed(e[1]));if(o===null)return null;try{let r=JSON.parse(o);return r===null||typeof r!="object"||Array.isArray(r)?null:JSON.stringify(r)}catch{return null}}function Ti(t){let e=t.trim().replace(/^\?/,"");if(e==="")return "{}";let o=Object.create(null);for(let r of e.split("&")){if(r==="")continue;let n=r.indexOf("="),i=n===-1?r:r.slice(0,n),a=n===-1?"":r.slice(n+1);try{o[decodeURIComponent(i.replace(/\+/g," "))]=decodeURIComponent(a.replace(/\+/g," "));}catch{return null}}return JSON.stringify(o)}var Po=class{constructor(){this.category="Encoding";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=(r.value??"").replace(/^from\s+/i,"").toLowerCase();n.emitOpcode(13),n.emitString(i),n.emitPluginCall("fromEncoding",2);}};var Fe=class{constructor(e){this.fn=e;this.category="Encoding";}parse(e,o,r){e.consume("LPAREN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("RPAREN"),r.emitPluginCall(this.fn,1);}};function xo(t){return t.type===3?t.value:null}function _o(t,e){return o=>{let r=xo(o);return r===null?chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",`"as ${t}" expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(r))}}var Td={base64:fi,url:Zl,"hex bytes":di,hexbytes:di,jwt:Ei,query:Ti},Ni={name:"solve-encoding",phrases:{"hex bytes":"CONVERTER_NAME","from base64":"FROM_ENCODING","from url":"FROM_ENCODING","from hex bytes":"FROM_ENCODING","from jwt":"FROM_ENCODING","from query":"FROM_ENCODING"},asConverters:{base64:_o("base64",pi),url:_o("url",ql),"hex bytes":_o("hex bytes",Jl)},infixParselets:{FROM_ENCODING:new Po},prefixParselets:{BASE64_FN:new Fe("base64"),JWT_FN:new Fe("jwt"),QUERY_FN:new Fe("query")},callFusions:{base64:"BASE64_FN",jwt:"JWT_FN",query:"QUERY_FN"},pluginFunctions:{base64:t=>_o("base64",pi)(t[0]),jwt:t=>{let e=xo(t[0]);if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",'jwt(...) expects text (a "quoted string")');let o=Ei(e);return o===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED","jwt(...): the input is not a valid JSON Web Token"):chunkGJZIJK2Q_cjs.t(o)},query:t=>{let e=xo(t[0]);if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",'query(...) expects text (a "quoted string")');let o=Ti(e);return o===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED","query(...): the input is not a valid query string"):chunkGJZIJK2Q_cjs.t(o)},fromEncoding:t=>{let e=xo(t[0]),o=String(t[1].value??"");if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",`"from ${o}" expects text (a "quoted string")`);let r=Td[o];if(!r)return chunkGJZIJK2Q_cjs.P("UNKNOWN_ENCODING",`"from ${o}" is not a known encoding (try base64, url or hex bytes)`);let n=r(e);return n===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED",`"from ${o}": the input is not valid ${o}`):chunkGJZIJK2Q_cjs.t(n)}},tokenCategories:{BASE64_FN:"function",JWT_FN:"function",QUERY_FN:"function"}};var Ao=class{constructor(){this.category="IP";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("ipLiteral",1);}};var He=class{constructor(e){this.pluginFn=e;this.category="IP";}parse(e,o,r){let n=e.peek(),i=e.peekAt(1);n?.type==="SLASH"&&i?.type==="NUMBER"?(e.consume(),e.consume(),r.emitOpcode(13),r.emitString(`|${i.value}`),r.emitPluginCall("ipLiteral",1)):e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall(this.pluginFn,1);}};var eu="IP_CIDR",Nd=chunkYBQOQTVL_cjs.c(eu),yd=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\/\d{1,2})?/,gd=8;function tu(t=72){let e="ip:ip-cidr-literal";return {name:e,priority:t,shape:[{types:["NUMBER"]}],match(o,r){let n=o[r];if(!n||n.type!=="NUMBER"||n.sourceEnd!==void 0||!/^\d{1,3}\./.test(n.text??""))return null;let i=n.text??"",a=n.offset+i.length,s=[n];for(let E=r+1;E<o.length&&s.length<gd;E++){let P=o[E];if(P.sourceEnd!==void 0||P.offset!==a||P.type!=="NUMBER"&&P.type!=="SLASH")break;i+=P.text??"",a=P.offset+(P.text?.length??0),s.push(P);}let l=yd.exec(i);if(l===null)return null;let u=chunk5TVI2UPZ_cjs.C(l[0]);if(u===null||u.addr===void 0)return null;let c=0,f=0;for(let E of s)if(f+=E.text?.length??0,c++,f>=l[0].length)break;if(f!==l[0].length)return null;let T=`${u.addr}|${u.prefix??""}`,N=new chunk6EYKVQT3_cjs.a(eu,Nd,T,l[0],n.offset,0,n.line,n.col,n.offset+l[0].length);return {consumed:c,replacement:[N],ruleName:e}}}}function gt(t,e){return t.type===17?t.value:chunkGJZIJK2Q_cjs.P("IP_EXPECTED",`"${e}" expects an IP address or subnet (e.g. 192.168.1.0/24)`)}function ru(t){let[e,o]=String(t[0].value??"").split("|"),r={...e!==""?{addr:Number(e)}:{},...o!==""?{prefix:Number(o)}:{}};return chunkGJZIJK2Q_cjs.J(r)}function ou(t){let e=gt(t[0],"hosts in");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NO_PREFIX",'"hosts in" needs a subnet with a prefix, e.g. 192.168.1.0/24'):chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.F(e.prefix))}function nu(t){let e=gt(t[0],"netmask of");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NO_PREFIX",'"netmask of" needs a prefix, e.g. /24 or 192.168.1.0/24'):chunkGJZIJK2Q_cjs.J({addr:chunk5TVI2UPZ_cjs.E(e.prefix)})}function iu(t){let e=gt(t[0],"broadcast of");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.addr===void 0||e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NEEDS_ADDRESS_AND_PREFIX",'"broadcast of" needs an address and a prefix, e.g. 192.168.1.0/24'):chunkGJZIJK2Q_cjs.J({addr:chunk5TVI2UPZ_cjs.G(e.addr,e.prefix)})}function au(t){let e=gt(t[0],"in");if(e instanceof chunkGJZIJK2Q_cjs.m)return e;let o=gt(t[1],"in");return o instanceof chunkGJZIJK2Q_cjs.m?o:e.addr===void 0?chunkGJZIJK2Q_cjs.P("IP_EXPECTED_ADDRESS",'"in" expects an address on the left'):o.addr===void 0||o.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_EXPECTED_BLOCK",'"in" expects a subnet on the right, e.g. 10.0.0.0/8'):chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.H(e.addr,o.addr,o.prefix))}function su(t){if(t.type===17){let e=t.value;return chunkGJZIJK2Q_cjs.n(e.addr??0)}return chunkGJZIJK2Q_cjs.n(Math.trunc(t.toNumber()))}var yi={name:"solve-ip",phrases:{"hosts in":"HOSTS_IN","netmask of":"NETMASK_OF","broadcast of":"BROADCAST_OF"},prefixParselets:{IP_CIDR:new Ao,HOSTS_IN:new He("hostsIn"),NETMASK_OF:new He("netmaskOf"),BROADCAST_OF:new He("broadcastOf")},normalizerRules:[tu()],pluginFunctions:{ipLiteral:ru,hostsIn:ou,netmaskOf:nu,broadcastOf:iu,ipInCidr:au},asConverters:{int:su},tokenCategories:{IP_CIDR:"number",HOSTS_IN:"keyword",NETMASK_OF:"keyword",BROADCAST_OF:"keyword"}};var Pd=chunkYBQOQTVL_cjs.c("UNIT");function mu(t=82){let e="fuel:l-per-100km";return {name:e,priority:t,shape:[{types:["UNIT","IDENT"],values:["l"]},{types:["SLASH"]}],match(o,r){let n=o[r],i=o[r+1],a=o[r+2],s=o[r+3];return !n||n.type!=="UNIT"&&n.type!=="IDENT"||(n.value??"").toLowerCase()!=="l"||i?.type!=="SLASH"||a?.type!=="NUMBER"||a.value!=="100"||s?.type!=="UNIT"||(s.value??"").toLowerCase()!=="km"?null:{consumed:4,replacement:[new chunk6EYKVQT3_cjs.a("UNIT",Pd,"l100km","l/100km",n.offset,0,n.line,n.col)],ruleName:e}}}}var gi={name:"solve-fuel",normalizerRules:[mu()]};var _d=chunkYBQOQTVL_cjs.c("UNIT");function lu(t=82){let e="derived:acceleration";return {name:e,priority:t,shape:[{types:["UNIT"],values:["m"]},{types:["SLASH"]}],match(o,r){let n=o[r],i=o[r+1],a=o[r+2],s=o[r+3],l=o[r+4];return !n||n.type!=="UNIT"||(n.value??"")!=="m"||i?.type!=="SLASH"||a?.type!=="UNIT"||(a.value??"")!=="s"||s?.type!=="CARET"||l?.type!=="NUMBER"||l.value!=="2"?null:{consumed:5,replacement:[new chunk6EYKVQT3_cjs.a("UNIT",_d,"mps2","m/s^2",n.offset,0,n.line,n.col)],ruleName:e}}}}function b(t){return e=>e.type!==6||!e.unit?chunkGJZIJK2Q_cjs.P("AS_UNIT_EXPECTED_QUANTITY",`"as ${t}" expects a quantity with a unit`):e.unit===t?e:chunkZKFCKAIX_cjs.d(e.unit,t)?chunkGJZIJK2Q_cjs.u(chunkZKFCKAIX_cjs.e(e.toNumber(),e.unit,t),t):chunkGJZIJK2Q_cjs.P("AS_UNIT_INCOMPATIBLE",`${e.unit} cannot be expressed as ${t}: they do not measure the same thing`)}var Pi={name:"solve-derived-units",normalizerRules:[lu()],asConverters:{n:b("N"),kn:b("kN"),j:b("J"),kj:b("kJ"),mj:b("MJ"),wh:b("Wh"),kwh:b("kWh"),w:b("W"),kw:b("kW"),mw:b("MW"),pa:b("Pa"),kpa:b("kPa"),mpa:b("MPa"),v:b("V"),mv:b("mV"),kv:b("kV")}};function _i(t){return [...t].length}function uu(t){return t.trim()}function cu(t){return [...t].reverse().join("")}function pu(t,e){return t.includes(e)}function fu(t,e){return t.startsWith(e)}function du(t,e){return t.endsWith(e)}function Eu(t,e,o){return e===""?t:t.split(e).join(o)}function Tu(t,e){let o=Math.trunc(e);return o<=0?"":t.repeat(o)}function Ro(t){return t.toUpperCase()}function Oo(t){return t.toLowerCase()}function Co(t){return t.replace(/\S+/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())}function Io(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Nu(t){let e=t.trim();return e===""?0:e.split(/\s+/).length}function yu(t){return t===""?0:t.split(/\r\n|\r|\n/).length}function ue(t){return t?.type===3?t.value:null}function Pt(t){return chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED",`${t} expects text (a "quoted string")`)}function ho(t,e){return o=>{let r=ue(o[0]);return r===null?Pt(t):chunkGJZIJK2Q_cjs.n(e(r))}}function Ge(t,e){return o=>{let r=ue(o[0]);return r===null?Pt(t):chunkGJZIJK2Q_cjs.t(e(r))}}function xd(t,e){if(e==="")return 0;let o=0,r=t.indexOf(e);for(;r!==-1;)o++,r=t.indexOf(e+"",r+e.length);return o}function xi(t,e){return o=>{let r=ue(o[0]),n=ue(o[1]);return r===null||n===null?Pt(t):chunkGJZIJK2Q_cjs.L(e(r,n))}}var gu={textLength:ho("length",_i),textWordCount:ho("words in",Nu),textCharCount:ho("characters in",_i),textLineCount:ho("lines in",yu),textTrim:Ge("trim",uu),textReverse:Ge("reverse",cu),textUpper:Ge('"as upper"',Ro),textLower:Ge('"as lower"',Oo),textTitle:Ge('"as title"',Co),textSlug:Ge('"as slug"',Io),textContains:xi("contains",pu),textStartsWith:xi("starts with",fu),textEndsWith:xi("ends with",du),textReplace:t=>{let e=ue(t[0]),o=ue(t[1]),r=ue(t[2]);if(e===null||o===null||r===null)return Pt("replace");let n=xd(e,o)*(r.length-o.length);return chunkGJZIJK2Q_cjs.d(Math.max(0,e.length+n),"characters"),chunkGJZIJK2Q_cjs.t(Eu(e,o,r))},textRepeat:t=>{let e=ue(t[0]);if(e===null)return Pt("repeat");let o=t[1];if(o?.type!==0)return chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED","repeat expects a count (a number)");let r=Math.max(0,Math.trunc(o.value));return chunkGJZIJK2Q_cjs.d(e.length*r,"characters"),chunkGJZIJK2Q_cjs.t(Tu(e,o.value))}};function Pe(t,e){return {category:"Text",parse(o,r,n){o.parseExpression(e,n),n.emitPluginCall(t,1);}}}function So(t){return {category:"Text",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitPluginCall(t,2);}}}var Pu={category:"Text",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(t,e,o,r){t.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r);let n=t.peek();n?.type==="STAR"&&(n.value??"").toLowerCase()==="times"&&t.consume(),r.emitPluginCall("textRepeat",2);}};var Lo={length:"textLength",upper:"textUpper",uppercase:"textUpper",lower:"textLower",lowercase:"textLower",title:"textTitle",titlecase:"textTitle",slug:"textSlug",slugify:"textSlug",replace:"textReplace",repeat:"textRepeat",words:"textWordCount",wordcount:"textWordCount",characters:"textCharCount",charcount:"textCharCount",lines:"textLineCount",linecount:"textLineCount"};var vo=class{constructor(){this.category="Text";}parse(e,o,r){let n=Lo[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown text function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};function wo(t,e){return o=>o.type!==3?chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED",`"as ${t}" expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(o.value))}var Ai={name:"solve-text",phrases:{"length of":"LENGTH_OF","words in":"WORDS_IN","characters in":"CHARACTERS_IN","lines in":"LINES_IN","starts with":"STARTS_WITH","ends with":"ENDS_WITH"},lexerVocabulary:{keywords:{trim:"TRIM",reverse:"REVERSE",contains:"CONTAINS",repeated:"REPEATED"}},prefixParselets:{LENGTH_OF:Pe("textLength",chunkZDJTDFTR_cjs.a.Lowest),WORDS_IN:Pe("textWordCount",chunkZDJTDFTR_cjs.a.Lowest),CHARACTERS_IN:Pe("textCharCount",chunkZDJTDFTR_cjs.a.Lowest),LINES_IN:Pe("textLineCount",chunkZDJTDFTR_cjs.a.Lowest),TRIM:Pe("textTrim",chunkZDJTDFTR_cjs.a.Prefix),REVERSE:Pe("textReverse",chunkZDJTDFTR_cjs.a.Prefix),TEXT_CALL:new vo},infixParselets:{CONTAINS:So("textContains"),STARTS_WITH:So("textStartsWith"),ENDS_WITH:So("textEndsWith"),REPEATED:Pu},asConverters:{upper:wo("upper",Ro),lower:wo("lower",Oo),title:wo("title",Co),slug:wo("slug",Io)},callFusions:Object.fromEntries(Object.keys(Lo).map(t=>[t,"TEXT_CALL"])),pluginFunctions:gu,tokenCategories:{LENGTH_OF:"function",WORDS_IN:"function",CHARACTERS_IN:"function",LINES_IN:"function",TRIM:"function",REVERSE:"function",TEXT_CALL:"function",CONTAINS:"operator",STARTS_WITH:"operator",ENDS_WITH:"operator",REPEATED:"operator"}};function _t(t){return new TextEncoder().encode(t)}function Ri(t){let e="";for(let o of t)e+=o.toString(16).padStart(2,"0");return e}var Ad=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let o=e;for(let r=0;r<8;r++)o=o&1?3988292384^o>>>1:o>>>1;t[e]=o>>>0;}return t})();function _u(t){let e=_t(t),o=4294967295;for(let r of e)o=Ad[(o^r)&255]^o>>>8;return o=(o^4294967295)>>>0,o.toString(16).padStart(8,"0")}function Rd(t){let e=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],o=new Int32Array(64);for(let N=0;N<64;N++)o[N]=Math.floor(Math.abs(Math.sin(N+1))*4294967296);let r=t.length*8,n=new Uint8Array(((t.length+8>>6)+1)*64);n.set(t),n[t.length]=128;let i=new DataView(n.buffer);i.setUint32(n.length-8,r>>>0,true),i.setUint32(n.length-4,Math.floor(r/4294967296)>>>0,true);let a=1732584193,s=4023233417,l=2562383102,u=271733878,c=(N,E)=>N<<E|N>>>32-E;for(let N=0;N<n.length;N+=64){let E=new Int32Array(16);for(let _=0;_<16;_++)E[_]=i.getUint32(N+_*4,true);let P=a,R=s,O=l,g=u;for(let _=0;_<64;_++){let h,S;_<16?(h=R&O|~R&g,S=_):_<32?(h=g&R|~g&O,S=(5*_+1)%16):_<48?(h=R^O^g,S=(3*_+5)%16):(h=O^(R|~g),S=7*_%16),h=h+P+o[_]+E[S]|0,P=g,g=O,O=R,R=R+c(h,e[_])|0;}a=a+P|0,s=s+R|0,l=l+O|0,u=u+g|0;}let f=new Uint8Array(16),T=new DataView(f.buffer);return T.setUint32(0,a>>>0,true),T.setUint32(4,s>>>0,true),T.setUint32(8,l>>>0,true),T.setUint32(12,u>>>0,true),f}function xu(t){return Ri(Rd(_t(t)))}function Od(t){let e=t.length*8,o=new Uint8Array(((t.length+8>>6)+1)*64);o.set(t),o[t.length]=128;let r=new DataView(o.buffer);r.setUint32(o.length-8,Math.floor(e/4294967296)>>>0),r.setUint32(o.length-4,e>>>0);let n=1732584193,i=4023233417,a=2562383102,s=271733878,l=3285377520,u=(N,E)=>N<<E|N>>>32-E,c=new Int32Array(80);for(let N=0;N<o.length;N+=64){for(let _=0;_<16;_++)c[_]=r.getUint32(N+_*4);for(let _=16;_<80;_++)c[_]=u(c[_-3]^c[_-8]^c[_-14]^c[_-16],1);let E=n,P=i,R=a,O=s,g=l;for(let _=0;_<80;_++){let h,S;_<20?(h=P&R|~P&O,S=1518500249):_<40?(h=P^R^O,S=1859775393):_<60?(h=P&R|P&O|R&O,S=2400959708):(h=P^R^O,S=3395469782);let q=u(E,5)+h+g+S+c[_]|0;g=O,O=R,R=u(P,30),P=E,E=q;}n=n+E|0,i=i+P|0,a=a+R|0,s=s+O|0,l=l+g|0;}let f=new Uint8Array(20),T=new DataView(f.buffer);return [n,i,a,s,l].forEach((N,E)=>T.setUint32(E*4,N>>>0)),f}function Au(t){return Ri(Od(_t(t)))}var Cd=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Id(t){let e=t.length*8,o=new Uint8Array(((t.length+8>>6)+1)*64);o.set(t),o[t.length]=128;let r=new DataView(o.buffer);r.setUint32(o.length-8,Math.floor(e/4294967296)>>>0),r.setUint32(o.length-4,e>>>0);let n=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),i=(u,c)=>u>>>c|u<<32-c,a=new Uint32Array(64);for(let u=0;u<o.length;u+=64){for(let g=0;g<16;g++)a[g]=r.getUint32(u+g*4);for(let g=16;g<64;g++){let _=i(a[g-15],7)^i(a[g-15],18)^a[g-15]>>>3,h=i(a[g-2],17)^i(a[g-2],19)^a[g-2]>>>10;a[g]=a[g-16]+_+a[g-7]+h|0;}let[c,f,T,N,E,P,R,O]=n;for(let g=0;g<64;g++){let _=i(E,6)^i(E,11)^i(E,25),h=E&P^~E&R,S=O+_+h+Cd[g]+a[g]|0,q=i(c,2)^i(c,13)^i(c,22),$e=c&f^c&T^f&T,pe=q+$e|0;O=R,R=P,P=E,E=N+S|0,N=T,T=f,f=c,c=S+pe|0;}n[0]=n[0]+c|0,n[1]=n[1]+f|0,n[2]=n[2]+T|0,n[3]=n[3]+N|0,n[4]=n[4]+E|0,n[5]=n[5]+P|0,n[6]=n[6]+R|0,n[7]=n[7]+O|0;}let s=new Uint8Array(32),l=new DataView(s.buffer);for(let u=0;u<8;u++)l.setUint32(u*4,n[u]>>>0);return s}function Ru(t){return Ri(Id(_t(t)))}var F=(1n<<64n)-1n,hd=[0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n];function Ou(t){let e=_t(t),o=((e.length+16>>7)+1)*128,r=new Uint8Array(o);r.set(e),r[e.length]=128;let n=BigInt(e.length)*8n,i=new DataView(r.buffer);i.setUint32(r.length-4,Number(n&0xffffffffn)),i.setUint32(r.length-8,Number(n>>32n&0xffffffffn));let a=[0x6a09e667f3bcc908n,0xbb67ae8584caa73bn,0x3c6ef372fe94f82bn,0xa54ff53a5f1d36f1n,0x510e527fade682d1n,0x9b05688c2b3e6c1fn,0x1f83d9abfb41bd6bn,0x5be0cd19137e2179n],s=(u,c)=>(u>>c|u<<64n-c)&F,l=new Array(80);for(let u=0;u<r.length;u+=128){for(let g=0;g<16;g++){let _=BigInt(i.getUint32(u+g*8)),h=BigInt(i.getUint32(u+g*8+4));l[g]=_<<32n|h;}for(let g=16;g<80;g++){let _=s(l[g-15],1n)^s(l[g-15],8n)^l[g-15]>>7n,h=s(l[g-2],19n)^s(l[g-2],61n)^l[g-2]>>6n;l[g]=l[g-16]+_+l[g-7]+h&F;}let[c,f,T,N,E,P,R,O]=a;for(let g=0;g<80;g++){let _=s(E,14n)^s(E,18n)^s(E,41n),h=E&P^~E&F&R,S=O+_+h+hd[g]+l[g]&F,q=s(c,28n)^s(c,34n)^s(c,39n),$e=c&f^c&T^f&T,pe=q+$e&F;O=R,R=P,P=E,E=N+S&F,N=T,T=f,f=c,c=S+pe&F;}a[0]=a[0]+c&F,a[1]=a[1]+f&F,a[2]=a[2]+T&F,a[3]=a[3]+N&F,a[4]=a[4]+E&F,a[5]=a[5]+P&F,a[6]=a[6]+R&F,a[7]=a[7]+O&F;}return a.map(u=>u.toString(16).padStart(16,"0")).join("")}var ko={md5:"hashMd5",sha1:"hashSha1",sha256:"hashSha256",sha512:"hashSha512",crc32:"hashCrc32"};function xt(t,e){return o=>{let r=o[0];return r?.type!==3?chunkGJZIJK2Q_cjs.P("HASH_EXPECTED_TEXT",`${t}(...) expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(r.value))}}var Cu={hashMd5:xt("md5",xu),hashSha1:xt("sha1",Au),hashSha256:xt("sha256",Ru),hashSha512:xt("sha512",Ou),hashCrc32:xt("crc32",_u)};var Bo=class{constructor(){this.category="Hash";}parse(e,o,r){let n=ko[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown hash function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var Oi={name:"solve-hash",prefixParselets:{HASH_CALL:new Bo},callFusions:Object.fromEntries(Object.keys(ko).map(t=>[t,"HASH_CALL"])),pluginFunctions:Cu,tokenCategories:{HASH_CALL:"function"}};var Iu="0123456789abcdef";function hu(){return Iu[Math.floor(Math.random()*16)]}function Sd(){let t="";for(let e=0;e<36;e++)e===8||e===13||e===18||e===23?t+="-":e===14?t+="4":e===19?t+=Iu[Math.floor(Math.random()*16)&3|8]:t+=hu();return t}function Ld(t){let e="";for(let o=0;o<t;o++)e+=hu();return e}var Su={randomUuid:()=>chunkGJZIJK2Q_cjs.t(Sd()),randomCoin:()=>chunkGJZIJK2Q_cjs.t(Math.random()<.5?"heads":"tails"),randomHex:t=>{let e=t[0];if(e?.type!==0)return chunkGJZIJK2Q_cjs.P("RANDOM_EXPECTED_COUNT","random hex expects a number of digits");let o=Math.trunc(e.value);return o<0?chunkGJZIJK2Q_cjs.P("RANDOM_EXPECTED_COUNT","random hex needs a count of 0 or more"):chunkGJZIJK2Q_cjs.t(Ld(o))},randomPick:t=>t.length===0?chunkGJZIJK2Q_cjs.P("RANDOM_PICK_EMPTY","pick needs at least one option"):t[Math.floor(Math.random()*t.length)],randomShuffle:t=>{let e=t[0];if(e?.type!==7)return chunkGJZIJK2Q_cjs.P("RANDOM_SHUFFLE_EXPECTED_LIST","shuffle expects a list, e.g. shuffle [1, 2, 3]");let o=e.value;if(o.rows!==1&&o.cols!==1)return chunkGJZIJK2Q_cjs.P("RANDOM_SHUFFLE_EXPECTED_LIST","shuffle expects a single row or column, not a full matrix");let r=o.data.slice();for(let n=r.length-1;n>0;n--){let i=Math.floor(Math.random()*(n+1));[r[n],r[i]]=[r[i],r[n]];}return chunkGJZIJK2Q_cjs.C(o.rows,o.cols,r)}};function Ci(t){return {category:"Random",parse(e,o,r){r.emitPluginCall(t,0);}}}function Ii(t){return {category:"Random",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall(t,1);}}}var Lu={category:"Random",parse(t,e,o){t.consume("LPAREN");let r=0;if(t.peek()?.type!=="RPAREN")for(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.match("COMMA");)t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.consume("RPAREN"),o.emitPluginCall("randomPick",r);}};var hi={name:"solve-random",phrases:{"random hex":"RANDOM_HEX"},lexerVocabulary:{keywords:{uuid:"UUID",coin:"COIN",shuffle:"SHUFFLE"}},prefixParselets:{UUID:Ci("randomUuid"),COIN:Ci("randomCoin"),RANDOM_HEX:Ii("randomHex"),SHUFFLE:Ii("randomShuffle"),PICK_CALL:Lu},callFusions:{pick:"PICK_CALL"},pluginFunctions:Su,tokenCategories:{UUID:"function",COIN:"function",RANDOM_HEX:"function",SHUFFLE:"function",PICK_CALL:"function"}};function ce(t){return t.reduce((e,o)=>e+o,0)/t.length}function vd(t){let e=ce(t);return t.reduce((o,r)=>o+(r-e)*(r-e),0)/t.length}function wd(t){return Math.sqrt(vd(t))}function Si(t,e){let o=ce(t),r=ce(e),n=0,i=0,a=0;for(let l=0;l<t.length;l++){let u=t[l]-o,c=e[l]-r;n+=u*c,i+=u*u,a+=c*c;}let s=Math.sqrt(i*a);return s===0?NaN:n/s}function Li(t,e){let o=ce(t),r=ce(e),n=0,i=0;for(let a=0;a<t.length;a++){let s=t[a]-o;n+=s*(e[a]-r),i+=s*s;}return i===0?NaN:n/i}function vu(t,e){return ce(e)-Li(t,e)*ce(t)}function wu(t,e){let o=Si(t,e);return o*o}function ku(t,e){let o=[...t].sort((a,s)=>a-s);if(o.length===1)return o[0];let r=e/100*(o.length-1),n=Math.floor(r),i=Math.ceil(r);return n===i?o[n]:o[n]+(r-n)*(o[i]-o[n])}function Bu(t,e){let o=wd(e);return o===0?NaN:(t-ce(e))/o}function kd(t){let e=t<0?-1:1,o=1/(1+.3275911*Math.abs(t)),r=1-((((1.061405429*o-1.453152027)*o+1.421413741)*o-.284496736)*o+.254829592)*o*Math.exp(-t*t);return e*r}function Mu(t){return .5*(1+kd(t/Math.SQRT2))}function Uu(t){return Math.exp(-0.5*t*t)/Math.sqrt(2*Math.PI)}function Uo(t){if(!t)return null;if(t.type===7){let e=t.value;return e.hasSymbolic||e.rows!==1&&e.cols!==1?null:e.data.slice()}if(t.type===8){let e=t.value,o=[];for(let r=Math.ceil(e.min);r<=e.max;r++)o.push(r);return o}return t.type===0?[t.value]:null}function Mo(t,e){return o=>{let r=Uo(o[0]),n=Uo(o[1]);return r===null||n===null?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LISTS",`${t} expects two lists, e.g. ${t} of [1, 2, 3] and [2, 4, 6]`):r.length!==n.length?chunkGJZIJK2Q_cjs.P("STAT_LENGTH_MISMATCH",`${t}: the two lists must be the same length (got ${r.length} and ${n.length})`):r.length<2?chunkGJZIJK2Q_cjs.P("STAT_TOO_FEW",`${t} needs at least two paired points`):chunkGJZIJK2Q_cjs.n(e(r,n))}}var Du={statCorrelation:Mo("correlation",Si),statSlope:Mo("slope",Li),statIntercept:Mo("intercept",vu),statRSquared:Mo("r squared",wu),statPercentile:t=>{let e=Uo(t[0]),o=t[1];if(e===null)return chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LIST","percentile expects a list, e.g. percentile([1, 2, 3], 90)");if(e.length===0)return chunkGJZIJK2Q_cjs.P("STAT_EMPTY","percentile needs at least one value");if(o?.type!==0)return chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_PERCENT","percentile needs a percentage, e.g. percentile([...], 90)");let r=o.value;return r<0||r>100?chunkGJZIJK2Q_cjs.P("STAT_PERCENT_RANGE","a percentile is between 0 and 100"):chunkGJZIJK2Q_cjs.n(ku(e,r))},statZScore:t=>{let e=t[0],o=Uo(t[1]);return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","zscore expects a value first, e.g. zscore(5, [1, 2, 3])"):o===null||o.length<2?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LIST","zscore expects a list of at least two values"):chunkGJZIJK2Q_cjs.n(Bu(e.value,o))},statNormalCdf:t=>{let e=t[0];return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","normalcdf expects a number"):chunkGJZIJK2Q_cjs.n(Mu(e.value))},statNormalPdf:t=>{let e=t[0];return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","normalpdf expects a number"):chunkGJZIJK2Q_cjs.n(Uu(e.value))}};function Do(t){return {category:"Statistics",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),r.emitPluginCall(t,2);}}}var bo={correlation:"statCorrelation",slope:"statSlope",intercept:"statIntercept",rsquared:"statRSquared",percentile:"statPercentile",zscore:"statZScore",normalcdf:"statNormalCdf",normalpdf:"statNormalPdf"};var Vo=class{constructor(){this.category="Statistics";}parse(e,o,r){let n=bo[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown statistics function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var vi={name:"solve-statistics",phrases:{"correlation of":"CORRELATION_OF","slope of":"SLOPE_OF","intercept of":"INTERCEPT_OF"},prefixParselets:{CORRELATION_OF:Do("statCorrelation"),SLOPE_OF:Do("statSlope"),INTERCEPT_OF:Do("statIntercept"),STAT_CALL:new Vo},callFusions:Object.fromEntries(Object.keys(bo).map(t=>[t,"STAT_CALL"])),pluginFunctions:Du,tokenCategories:{CORRELATION_OF:"function",SLOPE_OF:"function",INTERCEPT_OF:"function",STAT_CALL:"function"}};var Bd=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],bu={I:1,V:5,X:10,L:50,C:100,D:500,M:1e3};function wi(t){if(!Number.isInteger(t)||t<1||t>3999)return null;let e="",o=t;for(let[r,n]of Bd)for(;o>=r;)e+=n,o-=r;return e}function Vu(t){let e=t.trim().toUpperCase();if(e===""||!/^[MDCLXVI]+$/.test(e))return null;let o=0;for(let r=0;r<e.length;r++){let n=bu[e[r]],i=r+1<e.length?bu[e[r+1]]:0;o+=n<i?-n:n;}return wi(o)===e?o:null}function Fu(t){if(!Number.isInteger(t))return null;let e=Math.abs(t),o=e%100,r=e%10,n="th";return (o<11||o>13)&&(r===1?n="st":r===2?n="nd":r===3&&(n="rd")),`${t}${n}`}var Fo=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],Md=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],Ud=["","thousand","million","billion","trillion","quadrillion"];function Dd(t){if(t<20)return Fo[t];let e=Math.floor(t/10),o=t%10;return Md[e]+(o?`-${Fo[o]}`:"")}function bd(t){let e=Math.floor(t/100),o=t%100,r=[];return e&&r.push(`${Fo[e]} hundred`),o&&(e&&r.push("and"),r.push(Dd(o))),r.join(" ")}function Vd(t){if(t===0)return "zero";let e=[],o=t;for(;o>0;)e.push(o%1e3),o=Math.floor(o/1e3);let r=[];for(let i=e.length-1;i>=0;i--){if(e[i]===0)continue;let a=bd(e[i]);i>0&&(a+=` ${Ud[i]}`),r.push({scale:i,group:e[i],words:a});}let n="";for(let i=0;i<r.length;i++){if(i>0){let a=i===r.length-1;n+=a&&r[i].scale===0&&r[i].group<100?" and ":" ";}n+=r[i].words;}return n}function Hu(t){if(!Number.isFinite(t))return null;let e=Math.abs(t).toString();if(e.includes("e")||e.includes("E"))return null;let[o,r]=e.split("."),n=Vd(parseInt(o,10));return r&&(n+=" point "+[...r].map(i=>Fo[Number(i)]).join(" ")),(t<0?"minus ":"")+n}var Ho=class{constructor(){this.category="Numerals";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("romanFromString",1);}};function ki(t,e){return o=>{if(o.type!==0)return chunkGJZIJK2Q_cjs.P("NUMERAL_EXPECTED_NUMBER",`"as ${t}" expects a number`);let r=e(o.value);return r===null?chunkGJZIJK2Q_cjs.P("NUMERAL_OUT_OF_RANGE",`${o.value} cannot be written as ${t}`):chunkGJZIJK2Q_cjs.t(r)}}var Bi={name:"solve-numerals",phrases:{"from roman":"FROM_ROMAN"},asConverters:{roman:ki("roman",wi),ordinal:ki("ordinal",Fu),words:ki("words",Hu)},infixParselets:{FROM_ROMAN:new Ho},pluginFunctions:{romanFromString:t=>{let e=t[0];if(e?.type!==3)return chunkGJZIJK2Q_cjs.P("NUMERAL_EXPECTED_TEXT",'"from roman" expects text, e.g. "MMXXIV" from roman');let o=Vu(e.value);return o===null?chunkGJZIJK2Q_cjs.P("NUMERAL_INVALID_ROMAN",`"${e.value}" is not a valid Roman numeral`):chunkGJZIJK2Q_cjs.n(o)}},tokenCategories:{FROM_ROMAN:"operator"}};function Fd(t,e){for(t=Math.abs(t),e=Math.abs(e);e;)[t,e]=[e,t%e];return t}function Gu(t){if(t.length<2||t.some(o=>!Number.isInteger(o)||o<=0))return null;let e=t.reduce((o,r)=>Fd(o,r),0)||1;return t.map(o=>o/e).join(":")}var zu={category:"Ratio",parse(t,e,o){t.consume("LPAREN");let r=0;if(t.peek()?.type!=="RPAREN")for(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.match("COMMA");)t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.consume("RPAREN"),o.emitPluginCall("ratioReduce",r);}};var Mi={name:"solve-ratio",prefixParselets:{RATIO_CALL:zu},callFusions:{ratio:"RATIO_CALL"},pluginFunctions:{ratioReduce:t=>{let e=[];for(let r of t){if(r.type!==0)return chunkGJZIJK2Q_cjs.P("RATIO_EXPECTED_NUMBERS","ratio expects whole numbers, e.g. ratio(16, 9)");e.push(r.value);}let o=Gu(e);return o===null?chunkGJZIJK2Q_cjs.P("RATIO_INVALID","ratio needs at least two whole positive numbers"):chunkGJZIJK2Q_cjs.t(o)}},tokenCategories:{RATIO_CALL:"function"}};var _e=Math.PI;function H(t,e){let o=[];for(let r of e){if(!(r in t))return null;o.push(t[r]);}return o}var Ui=["circle","square","rectangle","triangle","sphere","cube","cylinder","cone"],Ku=["radius","side","width","height","base","length"];function $u(t,e,o){let r=i=>({error:`the ${t} of a ${e} needs its ${i}`}),n={error:`the ${t} of a ${e} is not one of the shapes this supports`};switch(`${t}:${e}`){case "area:circle":{let i=H(o,["radius"]);return i?{value:_e*i[0]**2}:r("radius")}case "perimeter:circle":case "circumference:circle":{let i=H(o,["radius"]);return i?{value:2*_e*i[0]}:r("radius")}case "area:square":{let i=H(o,["side"]);return i?{value:i[0]**2}:r("side")}case "perimeter:square":{let i=H(o,["side"]);return i?{value:4*i[0]}:r("side")}case "area:rectangle":{let i=H(o,["width","height"]);return i?{value:i[0]*i[1]}:r("width and height")}case "perimeter:rectangle":{let i=H(o,["width","height"]);return i?{value:2*(i[0]+i[1])}:r("width and height")}case "area:triangle":{let i=H(o,["base","height"]);return i?{value:.5*i[0]*i[1]}:r("base and height")}case "volume:sphere":{let i=H(o,["radius"]);return i?{value:4/3*_e*i[0]**3}:r("radius")}case "surface:sphere":{let i=H(o,["radius"]);return i?{value:4*_e*i[0]**2}:r("radius")}case "volume:cube":{let i=H(o,["side"]);return i?{value:i[0]**3}:r("side")}case "surface:cube":{let i=H(o,["side"]);return i?{value:6*i[0]**2}:r("side")}case "volume:cylinder":{let i=H(o,["radius","height"]);return i?{value:_e*i[0]**2*i[1]}:r("radius and height")}case "surface:cylinder":{let i=H(o,["radius","height"]);return i?{value:2*_e*i[0]*(i[0]+i[1])}:r("radius and height")}case "volume:cone":{let i=H(o,["radius","height"]);return i?{value:1/3*_e*i[0]**2*i[1]}:r("radius and height")}default:return n}}var Hd=new Set(Ui),Gd=new Set(Ku);function ze(t){return {category:"Geometry",parse(e,o,r){let n=e.peek(),i=(n?.value??"").toLowerCase();if(!n||n.type!=="IDENT"||!Hd.has(i))throw chunkGXO7TSXQ_cjs.c.parsing("GEOMETRY_EXPECTED_SHAPE",`Expected a shape (${Ui.join(", ")}) after "${t} of" but got ${n?`"${n.value}"`:"end of input"}`);e.consume(),r.emitOpcode(13),r.emitString(t),r.emitOpcode(13),r.emitString(i);let a=2;for(;;){let s=e.peek(),l=(s?.value??"").toLowerCase();if(!s||s.type!=="IDENT"||!Gd.has(l))break;e.consume(),r.emitOpcode(13),r.emitString(l),a++,e.parseExpression(chunkZDJTDFTR_cjs.a.Call,r),a++,e.peek()?.type==="COMMA"&&e.consume();}r.emitPluginCall("geometryCompute",a);}}}var Di={name:"solve-geometry",phrases:{"area of":"AREA_OF","perimeter of":"PERIMETER_OF","circumference of":"CIRCUMFERENCE_OF","volume of":"VOLUME_OF","surface area of":"SURFACE_AREA_OF"},prefixParselets:{AREA_OF:ze("area"),PERIMETER_OF:ze("perimeter"),CIRCUMFERENCE_OF:ze("circumference"),VOLUME_OF:ze("volume"),SURFACE_AREA_OF:ze("surface")},pluginFunctions:{geometryCompute:t=>{let e=String(t[0]?.value??""),o=String(t[1]?.value??""),r={};for(let i=2;i+1<t.length;i+=2){let a=String(t[i]?.value??""),s=t[i+1];if(s?.type===13)return s;r[a]=s?.toNumber()??NaN;}let n=$u(e,o,r);return n.error!==void 0?chunkGJZIJK2Q_cjs.P("GEOMETRY_ERROR",n.error):chunkGJZIJK2Q_cjs.n(n.value)}},tokenCategories:{AREA_OF:"function",PERIMETER_OF:"function",CIRCUMFERENCE_OF:"function",VOLUME_OF:"function",SURFACE_AREA_OF:"function"}};var zd={"speed of light":{value:299792458,unit:"m/s"},gravity:{value:9.80665,unit:"mps2"},"electron mass":{value:91093837015e-41,unit:"kg"},"proton mass":{value:167262192369e-38,unit:"kg"},avogadro:{value:602214076e15},planck:{value:662607015e-42},boltzmann:{value:1380649e-29},"elementary charge":{value:1602176634e-28},"gas constant":{value:8.314462618},tau:{value:6.283185307179586},"golden ratio":{value:1.618033988749895},phi:{value:1.618033988749895}};function Wu(t){return zd[t.toLowerCase()]??null}function z(t){return {category:"Constants",parse(e,o,r){r.emitOpcode(13),r.emitString(t),r.emitPluginCall("constantValue",1);}}}var bi={name:"solve-constants",phrases:{"speed of light":"SPEED_OF_LIGHT","electron mass":"ELECTRON_MASS","proton mass":"PROTON_MASS","elementary charge":"ELEMENTARY_CHARGE","gas constant":"GAS_CONSTANT","golden ratio":"GOLDEN_RATIO"},lexerVocabulary:{keywords:{gravity:"GRAVITY",avogadro:"AVOGADRO",planck:"PLANCK",boltzmann:"BOLTZMANN",tau:"TAU",phi:"PHI"}},prefixParselets:{SPEED_OF_LIGHT:z("speed of light"),ELECTRON_MASS:z("electron mass"),PROTON_MASS:z("proton mass"),ELEMENTARY_CHARGE:z("elementary charge"),GAS_CONSTANT:z("gas constant"),GOLDEN_RATIO:z("golden ratio"),GRAVITY:z("gravity"),AVOGADRO:z("avogadro"),PLANCK:z("planck"),BOLTZMANN:z("boltzmann"),TAU:z("tau"),PHI:z("phi")},pluginFunctions:{constantValue:t=>{let e=t[0]?.type===3?t[0].value:"",o=Wu(e);return o===null?chunkGJZIJK2Q_cjs.P("UNKNOWN_CONSTANT",`"${e}" is not a known constant`):o.unit?chunkGJZIJK2Q_cjs.u(o.value,o.unit):chunkGJZIJK2Q_cjs.n(o.value)}},tokenCategories:{SPEED_OF_LIGHT:"keyword",ELECTRON_MASS:"keyword",PROTON_MASS:"keyword",ELEMENTARY_CHARGE:"keyword",GAS_CONSTANT:"keyword",GOLDEN_RATIO:"keyword",GRAVITY:"keyword",AVOGADRO:"keyword",PLANCK:"keyword",BOLTZMANN:"keyword",TAU:"keyword",PHI:"keyword"}};function Yu(t,e){return t/(e*e)}function ju(t,e){return t*60/e}function Xu(t,e){let o=e/t,r=Math.floor(o),n=Math.round((o-r)*60);return n===60&&(r+=1,n=0),`${r}:${n.toString().padStart(2,"0")}`}var Go={bmi:"healthBmi",pace:"healthPace",speed:"healthSpeed"};var zo=class{constructor(){this.category="Health";}parse(e,o,r){let n=Go[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown health function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};function Ke(t){return t?.type===0?t.value:t?.type===6?t.toNumber():null}var Vi={name:"solve-health",prefixParselets:{HEALTH_CALL:new zo},callFusions:Object.fromEntries(Object.keys(Go).map(t=>[t,"HEALTH_CALL"])),pluginFunctions:{healthBmi:t=>{let e=Ke(t[0]),o=Ke(t[1]);return e===null||o===null||o===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","bmi(weight in kg, height in m), e.g. bmi(70, 1.75)"):chunkGJZIJK2Q_cjs.n(Yu(e,o))},healthPace:t=>{let e=Ke(t[0]),o=Ke(t[1]);return e===null||o===null||e===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","pace(distance in km, time in min), e.g. pace(10, 50)"):chunkGJZIJK2Q_cjs.t(`${Xu(e,o)} /km`)},healthSpeed:t=>{let e=Ke(t[0]),o=Ke(t[1]);return e===null||o===null||o===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","speed(distance in km, time in min), e.g. speed(10, 50)"):chunkGJZIJK2Q_cjs.u(ju(e,o),"km/h")}},tokenCategories:{HEALTH_CALL:"function"}};var YL=[on,nn,sn,cn,gn,Pn,_n,In,Sn,Ln,vn,wn,chunk7RC6RBS6_cjs.a,kn,Bn,Mn,Dn,Gn,ri,oi,ni,zn,Yn,ii,jn,li,ci,Ni,yi,gi,Pi,qn,Ai,Oi,hi,vi,Bi,Mi,Di,bi,Vi];
2
- exports.a=on;exports.b=nn;exports.c=sn;exports.d=cn;exports.e=gn;exports.f=Pn;exports.g=_n;exports.h=In;exports.i=hn;exports.j=Sn;exports.k=Ln;exports.l=vn;exports.m=wn;exports.n=kn;exports.o=Bn;exports.p=Mn;exports.q=Dn;exports.r=Gn;exports.s=zn;exports.t=$m;exports.u=Ym;exports.v=Xm;exports.w=Yn;exports.x=jn;exports.y=qn;exports.z=YL;//# sourceMappingURL=chunk-OPKJ2WWB.cjs.map
3
- //# sourceMappingURL=chunk-OPKJ2WWB.cjs.map
1
+ 'use strict';var chunkG2V33LFM_cjs=require('./chunk-G2V33LFM.cjs'),chunk7RC6RBS6_cjs=require('./chunk-7RC6RBS6.cjs'),chunkZDJTDFTR_cjs=require('./chunk-ZDJTDFTR.cjs'),chunkZSLVLMO5_cjs=require('./chunk-ZSLVLMO5.cjs'),chunkUURM7P3P_cjs=require('./chunk-UURM7P3P.cjs'),chunkZLRJ7TDP_cjs=require('./chunk-ZLRJ7TDP.cjs'),chunkQQHHZPEW_cjs=require('./chunk-QQHHZPEW.cjs'),chunkTMQ37JQY_cjs=require('./chunk-TMQ37JQY.cjs'),chunkTLG7VZRX_cjs=require('./chunk-TLG7VZRX.cjs'),chunk5TVI2UPZ_cjs=require('./chunk-5TVI2UPZ.cjs'),chunkFDKTESBC_cjs=require('./chunk-FDKTESBC.cjs'),chunkTPPM4QSS_cjs=require('./chunk-TPPM4QSS.cjs'),chunkE4HAKNBQ_cjs=require('./chunk-E4HAKNBQ.cjs'),chunkGJZIJK2Q_cjs=require('./chunk-GJZIJK2Q.cjs'),chunkZKFCKAIX_cjs=require('./chunk-ZKFCKAIX.cjs'),chunk6EYKVQT3_cjs=require('./chunk-6EYKVQT3.cjs'),chunkYBQOQTVL_cjs=require('./chunk-YBQOQTVL.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunkJ4LSAHCY_cjs=require('./chunk-J4LSAHCY.cjs'),chunkEZKR44MA_cjs=require('./chunk-EZKR44MA.cjs'),chunkGXO7TSXQ_cjs=require('./chunk-GXO7TSXQ.cjs');var ac=/^\d{1,3}(\.\d{3}){2,}$/,sc=/^\d*\.\d*$/,kt=class{constructor(){this.category="Arithmetic";}parse(e,o,r){let n,i=null,a=o.value;if(a.startsWith("0x")||a.startsWith("0X")){if(n=parseInt(a,16),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid hex literal: "${a}"`,{raw:a})}else if(a.startsWith("0b")||a.startsWith("0B")){if(n=parseInt(a.slice(2),2),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid binary literal: "${a}"`,{raw:a})}else if(a.startsWith("0o")||a.startsWith("0O")){if(n=parseInt(a.slice(2),8),Number.isNaN(n))throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`Invalid octal literal: "${a}"`,{raw:a})}else if(ac.test(a))n=parseFloat(a.split(".").join(""));else {let s=chunkS3DFU33X_cjs.a(e.getLocaleCode()),l=s.display.decimalSeparator,u=s.display.thousandsSeparator,c=a;u&&(c=c.split(u).join("")),l&&l!=="."&&(c=c.replace(l,".")),n=parseFloat(c),sc.test(c)&&(i=c);}if(i!==null){r.emitOpcode(16),r.emitString(i);return}r.emitOpcode(10),r.emitNumber(n);}};var Se=class{constructor(e){this.opcode=e;this.category="Arithmetic";}parse(e,o,r){e.parseExpression(60,r),r.emitOpcode(this.opcode);}};var M=class{constructor(e,o,r=false){this.opcode=o;this.category="Arithmetic";this.bindingPower=e,this.rightBindingPower=r?e-1:e;}parse(e,o,r,n){e.parseExpression(this.rightBindingPower,n),n.emitOpcode(this.opcode);}};var wt=class{constructor(){this.category="Arithmetic";}parse(e,o,r){e.parseExpression(0,r);let n=1;for(;e.match("COMMA");)e.parseExpression(0,r),n++;e.consume("RPAREN"),n>1&&(r.emitOpcode(152),r.emitIndex(1),r.emitIndex(n));}};var Ze=class{constructor(){this.category="Arithmetic";}parse(e,o,r){let n=o.type==="PI"?Math.PI:Math.E;r.emitOpcode(10),r.emitNumber(n);}};var mc={k:3,M:6,G:9,B:9,T:12},lc={thousand:3,thousands:3,million:6,millions:6,mn:6,billion:9,billions:9,bn:9,trillion:12,trillions:12,tn:12},uc=/^\d+(\.\d+)?$/;function cc(t,e){let o=t.indexOf("."),r=o===-1?t:t.slice(0,o),n=o===-1?"":t.slice(o+1);n.length<e&&(n=n.padEnd(e,"0"));let i=r+n.slice(0,e),a=n.slice(e);return a?`${i}.${a}`:i}function Ha(t=65){return {name:"arithmetic:large-number-suffix",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT","UNIT"]}],match(e,o){let r=e[o];if(r.type!=="NUMBER"||!uc.test(r.text))return null;let n=e[o+1];if(!n||n.type!=="IDENT"&&n.type!=="UNIT")return null;let i=r.offset+r.text.length===n.offset,a=n.type==="UNIT"?void 0:lc[n.value.toLowerCase()],s=i?mc[n.value]??a:a;if(s===void 0)return null;let l=cc(r.text,s);return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b("NUMBER",l,e.slice(o,o+2))],ruleName:"arithmetic:large-number-suffix"}}}}var mn={name:"solve-arithmetic",prefixParselets:{NUMBER:new kt,LPAREN:new wt,PI:new Ze,E:new Ze,PLUS:new Se(27),MINUS:new Se(26),BIT_NOT:new Se(36)},infixParselets:{PLUS:new M(chunkZDJTDFTR_cjs.a.Sum,20),AND_CONJ:new M(chunkZDJTDFTR_cjs.a.Conjunction,20),MINUS:new M(chunkZDJTDFTR_cjs.a.Sum,21),STAR:new M(chunkZDJTDFTR_cjs.a.Product,22),SLASH:new M(chunkZDJTDFTR_cjs.a.Product,23),MOD:new M(chunkZDJTDFTR_cjs.a.Product,24),CARET:new M(chunkZDJTDFTR_cjs.a.Exponent,25,true),TIMES_BY:new M(chunkZDJTDFTR_cjs.a.Product,22),MULTIPLY_BY:new M(chunkZDJTDFTR_cjs.a.Product,22),DIVIDE_BY:new M(chunkZDJTDFTR_cjs.a.Product,23),LSHIFT:new M(chunkZDJTDFTR_cjs.a.Shift,30),RSHIFT:new M(chunkZDJTDFTR_cjs.a.Shift,31),URSHIFT:new M(chunkZDJTDFTR_cjs.a.Shift,32),BIT_AND:new M(chunkZDJTDFTR_cjs.a.BitwiseAnd,33),BIT_OR:new M(chunkZDJTDFTR_cjs.a.BitwiseOr,34),BIT_XOR:new M(chunkZDJTDFTR_cjs.a.BitwiseXor,35)},normalizerRules:[Ha()]};var Mt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){n.emitOpcode(10),n.emitNumber(100),n.emitOpcode(23),n.emitOpcode(74);}};var Bt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){if(Ka(e,"what")){e.consume(),this.parseWhatRate(e,n);return}this.parseWhatBase(e,n);}parseWhatRate(e,o){if(!e.match("PERCENT"))throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_PERCENT",'Expected "%" after "is what", as in "20 is what % of 200"');let r=pc(e);if(r===null){o.emitOpcode(74);return}e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),o.emitOpcode(23),r==="off"?(o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(2),o.emitOpcode(21)):r==="on"&&(o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(21)),o.emitOpcode(74);}parseWhatBase(e,o){if(e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),e.match("TO")){za(e,"what",'"81 is 9 to what power"'),za(e,"power",'"81 is 9 to what power"'),o.emitOpcode(51),o.emitIndex(Ga),o.emitIndex(1),o.emitOpcode(2),o.emitOpcode(51),o.emitIndex(Ga),o.emitIndex(1),o.emitOpcode(2),o.emitOpcode(23);return}let r=e.match("OF_WHAT")?"of":e.match("OFF_WHAT")?"off":e.match("ON_WHAT")?"on":null;if(r===null)throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_PREPOSITION",'Expected "of what", "off what" or "on what", as in "20 is 10% of what"');if(r==="of"){o.emitOpcode(23);return}o.emitOpcode(10),o.emitNumber(1),r==="off"?(o.emitOpcode(2),o.emitOpcode(21)):o.emitOpcode(20),o.emitOpcode(23);}},Ga=5;function Ka(t,e){return (t.peek()?.text??"").toLowerCase()===e}function za(t,e,o){if(!Ka(t,e))throw chunkGXO7TSXQ_cjs.c.parsing("IS_WHAT_EXPECTED_WORD",`Expected "${e}" here, as in ${o}`);t.consume();}function pc(t){if(t.match("OF"))return "of";let e=(t.peek()?.text??"").toLowerCase();return e==="off"||e==="on"?(t.consume(),e):null}var Je=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(2),n.emitOpcode(10),n.emitNumber(1),this.sign===1?n.emitOpcode(20):(n.emitOpcode(2),n.emitOpcode(21)),n.emitOpcode(22);}};function $a(t=68){return {name:"percentage:on-off",priority:t,shape:[{types:["PERCENT"]},{types:["IDENT"],values:["on","off"]}],match(e,o){if(e[o]?.type!=="PERCENT")return null;let r=e[o+1];if(r?.type!=="IDENT")return null;let n=(r.text??r.value??"").toLowerCase();return n!=="on"&&n!=="off"||(e[o+2]?.text??"").toLowerCase()==="what"?null:{consumed:2,replacement:[e[o],chunkZSLVLMO5_cjs.b(n==="on"?"PCT_ON":"PCT_OFF",n,[r])],ruleName:"percentage:on-off"}}}}var Ut=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(22);}};var Dt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23);}};var et=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){n.emitOpcode(10),n.emitNumber(1),this.sign===1?n.emitOpcode(20):(n.emitOpcode(2),n.emitOpcode(21)),e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23);}};var tt=class{constructor(e){this.multiplier=e;this.category="Percentage";}parse(e,o,r){e.parseExpression(0,r);let n=e.peek();n&&(n.type==="IDENT"||n.type==="BY")&&e.consume(),r.emitOpcode(10),r.emitNumber(1),e.parseExpression(0,r),e.peek()?.type==="PERCENT"&&e.consume(),r.emitOpcode(this.multiplier>0?20:21),r.emitOpcode(22);}};var rt=class{constructor(e){this.multiplier=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(2),n.emitOpcode(this.multiplier>0?20:21),n.emitOpcode(22);}};var bt=class{constructor(){this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){if(o.type==="UNIT")return;let i=e.peek();if(i&&((i.type==="UNIT"||i.type==="IDENT")&&chunkJ4LSAHCY_cjs.b(i.value)||i.type==="IN")){e.consume(),n.emitOpcode(13),n.emitString(i.value),n.emitOpcode(84);return}e.parseExpression(this.bindingPower,n),n.emitOpcode(2),n.emitOpcode(23),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(21),n.emitOpcode(74);}};var fc={one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12};function dc(t){if(t.type==="NUMBER"){let e=Number(t.value);return Number.isInteger(e)&&e>=0?e:null}return t.type==="IDENT"?fc[t.value.toLowerCase()]??null:null}var ot=class{constructor(e){this.sign=e;this.category="Percentage";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(10),n.emitNumber(1),n.emitOpcode(2),n.emitOpcode(this.sign>0?20:21);let i=this.tryConsumeRepeat(e);i!==null&&(n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(25)),n.emitOpcode(22),this.consumeChainThen(e);}tryConsumeRepeat(e){let o=e.peek(),r=e.peekAt(1);if(!o||!r||r.type!=="STAR"||r.value.toLowerCase()!=="times")return null;let n=dc(o);return n===null?null:(e.consume(),e.consume(),n)}consumeChainThen(e){if(e.peek()?.type!=="THEN")return;let o=e.peekAt(1)?.type;(o==="PCT_UP"||o==="PCT_DOWN")&&e.consume();}};function Wa(t,e){let o=t[e];if(o?.type!=="IDENT")return null;let r=(o.text??o.value??"").toLowerCase();return r!=="up"&&r!=="down"||t[e+1]?.type!=="NUMBER"||t[e+2]?.type!=="PERCENT"?null:chunkZSLVLMO5_cjs.b(r==="up"?"PCT_UP":"PCT_DOWN",r,[o])}function Ya(t=68){return {name:"percentage:up-down",priority:t,shape:[{types:["NUMBER","RPAREN","IDENT"]}],match(e,o){let r=e[o];if(r&&(r.type==="NUMBER"||r.type==="RPAREN")){let i=Wa(e,o+1);if(i)return {consumed:2,replacement:[r,i],ruleName:"percentage:up-down"}}let n=Wa(e,o);return n?{consumed:1,replacement:[n],ruleName:"percentage:up-down"}:null}}}var ln={name:"solve-percentage",phrases:{"of what is":"OF_WHAT_IS","of what":"OF_WHAT","off what":"OFF_WHAT","on what":"ON_WHAT","on what is":"ON_WHAT_IS","off what is":"OFF_WHAT_IS"},infixParselets:{PERCENT:new Mt,IS:new Bt,PCT_ON:new Je(1),PCT_OFF:new Je(-1),OF:new Ut,OF_WHAT_IS:new Dt,ON_WHAT_IS:new et(1),OFF_WHAT_IS:new et(-1),TO:new bt,INCREASE_BY:new rt(1),DECREASE_BY:new rt(-1),PCT_UP:new ot(1),PCT_DOWN:new ot(-1)},prefixParselets:{INCREASE:new tt(1),DECREASE:new tt(-1)},normalizerRules:[$a(),Ya()]};var un={sqrt:0,abs:1,sin:2,cos:3,tan:4,log:5,ceil:6,floor:7,round:8,min:9,max:10,asin:11,acos:12,atan:13,atan2:14,arcsin:11,arccos:12,arctan:13,sind:87,cosd:88,tand:89,asind:90,acosd:91,atand:92,sinh:15,cosh:16,tanh:17,asinh:18,acosh:19,atanh:20,cbrt:21,clz32:22,expm1:23,exp:24,fround:25,hypot:26,imul:27,log10:28,log1p:29,log2:30,pow:31,random:32,sign:33,trunc:34,degtorad:35,radtodeg:36,gcd:38,lcm:39,permutation:40,combination:41,hex:48,bin:49,int:50,compoundinterest:51,interestearned:52,compoundinterestrate:53,compoundinterestyears:54,loanrepayment:55,loaninterest:56,monthlypayment:57,taxadd:58,taxremove:59,inflationadjust:60,root:61,fact:62,factorial:62,transpose:63,det:64,inv:65,dot:66},Vt=class{constructor(){this.category="Function";}parse(e,o,r){let n=o.value.toLowerCase(),i=un[n];if(i===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown function: ${n}`,{functionName:n});e.consume("LPAREN");let a=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),a++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),a++;e.consume("RPAREN"),r.emitOpcode(51),r.emitIndex(i),r.emitIndex(a);}};var cn={name:"solve-function",prefixParselets:{FUNC:new Vt}};var de=class{constructor(e=0){this.category="Date/Time";this.dayOffset=e;}parse(e,o,r){r.emitOpcode(90),this.dayOffset!==0&&(r.emitOpcode(10),r.emitNumber(this.dayOffset),r.emitOpcode(13),r.emitString("days"),r.emitOpcode(80),r.emitOpcode(20));}};var Ec={SUNDAY:0,MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6},nt=class{constructor(e){this.direction=e;this.category="Date/Time";}parse(e,o,r){let n=e.peek(),i=n?Ec[n.type]:void 0;if(i===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("MISSING_WEEKDAY",`"${o.value}" must be followed by a day of the week (e.g. "${o.value} Saturday")`,{keyword:o.value,actualType:n?.type,actualValue:n?.value});e.consume(),r.emitOpcode(90),r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(this.direction==="next"?93:94);}};var it=class{constructor(e){this.direction=e;this.category="Date/Time";}parse(e,o,r){let n=o.value;this.direction==="until"?(e.parseExpression(0,r),r.emitOpcode(90)):(r.emitOpcode(90),e.parseExpression(0,r)),r.emitOpcode(21),r.emitOpcode(13),r.emitString(n),r.emitOpcode(84);}};var Ft=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(0,r),r.emitPluginCall("workdaysInDuration",1);}};var at=class{constructor(e){this.direction=e;this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Sum,n),n.emitOpcode(96),n.emitByte(this.direction==="backward"?1:0);}};var Ht=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(97);}};var ee=class{constructor(e,o){this.functionName=e;this.mode=o;this.category="Date/Time";}parse(e,o,r){this.mode==="in"?(r.emitOpcode(90),e.parseExpression(0,r),r.emitOpcode(20)):e.peek()?e.parseExpression(0,r):r.emitOpcode(90),r.emitPluginCall(this.functionName,1);}};var Gt=class{constructor(){this.category="Date/Time";}parse(e,o,r){let n=o.value;e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("spanBetweenDates",2),r.emitOpcode(13),r.emitString(n),r.emitOpcode(84);}};var st=class{constructor(e){this.functionName=e;this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall(this.functionName,1);}};var zt=class{constructor(){this.category="Date/Time";}parse(e,o,r){r.emitOpcode(90),r.emitPluginCall("toTimestampFromAny",1);}};var Kt=class{constructor(){this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("toDateFromAny",1);}};var $t=class{constructor(){this.category="Date/Time";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("toTimestampFromAny",1);}};var Tc="datetimeLiteralGrain",Wt=class{constructor(){this.category="Date/Time";}parse(e,o,r){r.emitOpcode(95),r.emitNumber(Number(o.value));let{grain:n,zone:i}=chunk7RC6RBS6_cjs.d(o.text);n!=="date"&&(r.emitOpcode(13),r.emitString(n),r.emitOpcode(13),r.emitString(i??""),r.emitPluginCall(Tc,3));}};var Yt=class{constructor(){this.category="Date/Time";}parse(e,o,r){let n=o.fault??{code:"DATE_NOT_A_CALENDAR_DAY",message:`"${o.value}" is not a date this engine can read.`};r.emitOpcode(13),r.emitString(n.code),r.emitOpcode(13),r.emitString(n.message),r.emitPluginCall("dateLiteralFault",2);}};var jt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.consume("OF"),e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r),r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("nthWeekdayOfMonth",2);}};var Le=class{constructor(e){this.offsetMonths=e;this.category="Date/Time";}parse(e,o,r){r.emitOpcode(90),r.emitOpcode(10),r.emitNumber(this.offsetMonths),r.emitPluginCall("monthAnchorShift",2);}};var Nc=new Set(["year","years","month","months","day","days"]),Xt=class{constructor(){this.category="Date/Time";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r),this.wordIs(e.peek(),"on")?(e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r)):r.emitOpcode(90);let n=this.consumeBreakdown(e)?"ymd":"years";r.emitOpcode(13),r.emitString(n),r.emitPluginCall("ageBetween",3);}wordIs(e,o){return e?String(e.value??e.text??"").toLowerCase()===o:false}consumeBreakdown(e){if(e.peek()?.type!=="IN")return false;e.consume();let o=false;for(;;){let r=e.peek();if(!r)break;let n=String(r.value??r.text??"").toLowerCase();if(r.type==="UNIT"&&Nc.has(n))o=true,e.consume();else if(r.type==="COMMA"||r.type==="AND_CONJ"||n==="and")e.consume();else break}return o}};function yc(t){let e=t[0],o;if(e.type===6&&e.unit){if(chunkZKFCKAIX_cjs.c(e.unit)!=="time")return chunkGJZIJK2Q_cjs.P("WORKDAYS_IN_EXPECTED_DURATION",`"workdays in" expects a time duration, got unit "${e.unit}"`);o=chunkZKFCKAIX_cjs.e(e.toNumber(),e.unit,"day");}else o=e.toNumber();let r=o<0?-1:1,n=Math.abs(o),i=Math.floor(n/7),a=n-i*7,s=r*(i*5+Math.min(a,5));return chunkGJZIJK2Q_cjs.n(s)}var gc=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function mt(t,e){return t.type===4?t.toNumber():chunkGJZIJK2Q_cjs.P("DATE_FIELD_EXPECTED_DATE",`"${e}" expects a date, got ${chunkGJZIJK2Q_cjs.g[t.type]??"an unsupported value"}`)}function Pc(t,e){let o=mt(t[0],"weekday");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.t(gc[chunkTPPM4QSS_cjs.c(e).fields(o).weekday])}var _c=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ac(t,e){let o=mt(t[0],"month");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.t(_c[chunkTPPM4QSS_cjs.c(e).fields(o).month0])}function xc(t,e){let o=mt(t[0],"week");if(typeof o!="number")return o;let r=chunkTPPM4QSS_cjs.c(e).fields(o);return chunkGJZIJK2Q_cjs.n(chunkE4HAKNBQ_cjs.e(r.year,r.month0,r.day))}function ja(t,e){let o=e.fields(t).weekday;return o===0||o===6}function Rc(t,e){let o=mt(t[0],"is a weekend");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.L(ja(o,chunkTPPM4QSS_cjs.c(e)))}function Oc(t,e){let o=mt(t[0],"is a workday");return typeof o!="number"?o:chunkGJZIJK2Q_cjs.L(!ja(o,chunkTPPM4QSS_cjs.c(e)))}var Cc=864e5;function Ic(t,e){let o=t[0].toNumber(),r=t[1].toNumber(),n=chunkTPPM4QSS_cjs.c(e),i=n.fields(o),a=n.fields(r);if(n.localMidnight(i.year,i.month0,i.day)===o&&n.localMidnight(a.year,a.month0,a.day)===r){let l=Math.abs(chunkE4HAKNBQ_cjs.c(a.year,a.month0,a.day)-chunkE4HAKNBQ_cjs.c(i.year,i.month0,i.day));return chunkGJZIJK2Q_cjs.u(l*Cc,"ms")}return chunkGJZIJK2Q_cjs.u(Math.abs(o-r),"ms")}function hc(t,e){let o=t[0];if(o.type===4)return o;if(o.type===3){let r=chunk7RC6RBS6_cjs.c(o.value,chunkTPPM4QSS_cjs.c(e));return r===null?chunkGJZIJK2Q_cjs.P("INVALID_ISO8601_STRING",`"${o.value}" is not a recognizable ISO8601 date/time string`):chunkGJZIJK2Q_cjs.M(r)}return chunkGJZIJK2Q_cjs.M(chunk7RC6RBS6_cjs.f(o.toNumber()))}function Sc(t){let e=t[0],o=t[1].value,r=t[2].value;return chunkGJZIJK2Q_cjs.M(e.toNumber(),o,r===""?void 0:r)}function Lc(t,e){let o=t[0];if(o.type===3){let r=chunk7RC6RBS6_cjs.c(o.value,chunkTPPM4QSS_cjs.c(e));return r===null?chunkGJZIJK2Q_cjs.P("INVALID_ISO8601_STRING",`"${o.value}" is not a recognizable ISO8601 date/time string`):chunkGJZIJK2Q_cjs.n(Math.floor(r/1e3))}return chunkGJZIJK2Q_cjs.n(Math.floor(o.toNumber()/1e3))}var Xa=yc,pn=Pc,fn=Ac,dn=xc,Qa=Rc,qa=Oc,Za=Ic,Ja=hc,es=Lc,ts=Sc;function os(t,e,o,r,n){let i=n.fields(n.localMidnight(t,e,1)).weekday,s=1+(o-i+7)%7+(r-1)*7;return s<1||s>chunkE4HAKNBQ_cjs.b(t,e)?null:n.localMidnight(t,e,s)}function ns(t,e,o,r){let n=chunkE4HAKNBQ_cjs.b(t,e),a=(r.fields(r.localMidnight(t,e,n)).weekday-o+7)%7;return r.localMidnight(t,e,n-a)}function is(t,e,o){let r=o.fields(t),n=o.fields(e),i=n.year-r.year;return (n.month0<r.month0||n.month0===r.month0&&n.day<r.day)&&i--,i}function rs(t,e){let o=t.year,r=t.month0+e,n=o+Math.floor(r/12),i=(r%12+12)%12,a=Math.min(t.day,chunkE4HAKNBQ_cjs.b(n,i));return {year:n,month0:i,day:a}}function as(t,e,o){let r=o.fields(t),n=o.fields(e),i=(n.year-r.year)*12+(n.month0-r.month0),a=rs(r,i);o.localMidnight(a.year,a.month0,a.day)>e&&(i--,a=rs(r,i));let s=chunkE4HAKNBQ_cjs.c(n.year,n.month0,n.day)-chunkE4HAKNBQ_cjs.c(a.year,a.month0,a.day);return {years:Math.floor(i/12),months:i%12,days:s}}function ss(t,e,o){let r=o.fields(t);return o.localMidnight(r.year,r.month0+e,1)}function qt(t,e){return t.type===4?t.toNumber():chunkGJZIJK2Q_cjs.P("DATE_EXPECTED",`"${e}" expects a date, got ${chunkGJZIJK2Q_cjs.g[t.type]??"an unsupported value"}`)}function vc(t,e){let o=qt(t[0],"nth weekday of month");if(typeof o!="number")return o;let r=String(t[1].value??""),[n,i]=r.split(":"),a=Number(i),s=chunkTPPM4QSS_cjs.c(e),l=s.fields(o),u=l.year,c=l.month0;if(n==="last")return chunkGJZIJK2Q_cjs.M(ns(u,c,a,s));let f=Number(n),T=os(u,c,a,f,s);return T===null?chunkGJZIJK2Q_cjs.P("NTH_WEEKDAY_OUT_OF_RANGE",`there is no ${n}${kc(f)} occurrence of that weekday in the month`):chunkGJZIJK2Q_cjs.M(T)}function kc(t){let e=t%100;if(e>=11&&e<=13)return "th";switch(t%10){case 1:return "st";case 2:return "nd";case 3:return "rd";default:return "th"}}function wc(t,e){let o=qt(t[0],"month anchor");if(typeof o!="number")return o;let r=t[1].toNumber();return chunkGJZIJK2Q_cjs.M(ss(o,r,chunkTPPM4QSS_cjs.c(e)))}var Mc="ymd";function Bc(t,e){let o=qt(t[0],"age of");if(typeof o!="number")return o;let r=qt(t[1],"age of");if(typeof r!="number")return r;let n=String(t[2].value??"years"),i=chunkTPPM4QSS_cjs.c(e);return n===Mc?chunkGJZIJK2Q_cjs.t(Uc(as(o,r,i))):chunkGJZIJK2Q_cjs.u(is(o,r,i),"years")}function Uc(t){let e=[];return t.years!==0&&e.push(Qt(t.years,"year")),t.months!==0&&e.push(Qt(t.months,"month")),t.days!==0&&e.push(Qt(t.days,"day")),e.length===0?Qt(0,"day"):e.join(", ")}function Qt(t,e){return `${t} ${e}${Math.abs(t)===1?"":"s"}`}var ms=vc,ls=wc,us=Bc;function Dc(t){return chunkGJZIJK2Q_cjs.P(String(t[0].value??"DATE_NOT_A_CALENDAR_DAY"),String(t[1].value??""))}var cs=Dc;var bc={SUNDAY:0,MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6},ps="NTH_WEEKDAY",Vc=chunkYBQOQTVL_cjs.c(ps),Fc=/^(\d+)(st|nd|rd|th)$/i;function fs(t=66){let e="datetime:nth-weekday";return {name:e,priority:t,unshapedReason:"Reads an ordinal that may be the LAST keyword, a number, or a word like `third`, so no fixed first-token set describes it.",match(o,r){let n=o[r];if(!n)return null;let i=null,a=0;if(n.type==="LAST")i="last",a=1;else {let f=o[r+1];if(!f||(n.sourceEnd??n.offset+(n.text?.length??0))!==f.offset)return null;let N=(n.text??"")+(f.text??""),E=Fc.exec(N);if(!E)return null;i=String(Number(E[1])),a=2;}let s=o[r+a],l=s?bc[s.type]:void 0;if(l===void 0||o[r+a+1]?.type!=="OF")return null;let u=`${i}:${l}`,c=new chunk6EYKVQT3_cjs.a(ps,Vc,u,u,n.offset,0,n.line,n.col);return {consumed:a+1,replacement:[c],ruleName:e}}}}function ds(t=60){return {name:"datetime:until-since",priority:t,shape:[{types:["UNIT"]},{types:["UNTIL","SINCE"]}],match(e,o){if(o+1>=e.length)return null;let r=e[o],n=e[o+1];if(r.type!=="UNIT"||n.type!=="UNTIL"&&n.type!=="SINCE")return null;let i=n.type==="UNTIL"?"UNTIL_UNIT":"SINCE_UNIT";return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b(i,r.value,[r,n])],ruleName:`datetime:${n.type.toLowerCase()}`}}}}function Es(t=60){return {name:"datetime:between-unit",priority:t,startTokenTypes:["UNIT","IDENT"],match(e,o){let r=o,n=0;e[o]?.value?.toLowerCase()==="how"&&e[o+1]?.value?.toLowerCase()==="many"&&(r=o+2,n=2);let i=e[r],a=e[r+1];if(!i||!a||i.type!=="UNIT")return null;let s=a.type==="BETWEEN",l=a.type==="UNTIL"||a.type==="SINCE";if(!s&&!l||l&&n===0)return null;let u=e.slice(o,r+2);return l?{consumed:n+2,replacement:[i,a],ruleName:"datetime:how-many"}:{consumed:n+2,replacement:[chunkZSLVLMO5_cjs.b("BETWEEN_UNIT",i.value,u)],ruleName:"datetime:between"}}}}function Ts(t=70){return {name:"datetime:workday-rate-denominator",priority:t,shape:[{types:["SLASH"]},{types:["UNIT"],values:["workday","workdays"]}],match(e,o){let r=e[o];if(r.type!=="SLASH")return null;let n=e[o+1];if(!n||n.type!=="UNIT"||n.value!=="workday"&&n.value!=="workdays")return null;let i={...n,type:"NUMBER",typeId:chunkYBQOQTVL_cjs.c("NUMBER"),value:"1",text:"1"};return {consumed:2,replacement:[r,i,n],ruleName:"datetime:workday-rate-denominator"}}}}var Hc=93,Gc={q1:[0,2],q2:[3,5],q3:[6,8],q4:[9,11]};function zc(t){return chunkE4HAKNBQ_cjs.b(t,1)===29?366:365}function Kc(t){return t.fields(t.now()).year}var Zt=class{constructor(){this.category="Datetime";}parse(e,o,r){let n=this.readPeriodDays(e);r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(51),r.emitIndex(Hc),r.emitIndex(1);}readPeriodDays(e){let o=e.getCalendar(),r=e.peek(),n=(r?.text??r?.value??"").toLowerCase(),i=Gc[n];if(i!==void 0){e.consume();let s=this.readOptionalYear(e)??Kc(o),l=0;for(let u=i[0];u<=i[1];u++)l+=chunkE4HAKNBQ_cjs.b(s,u);return l}if(r?.type==="DATETIME_LITERAL"){e.consume();let s=o.fields(Number(r.value));return chunkE4HAKNBQ_cjs.b(s.year,s.month0)}let a=this.readOptionalYear(e);if(a!==null)return zc(a);throw chunkGXO7TSXQ_cjs.c.parsing("DAYS_IN_EXPECTED_PERIOD",'Expected a month, quarter or year, as in "days in February 2020" or "days in Q3"')}readOptionalYear(e){let o=e.peek();if(o?.type!=="NUMBER")return null;let r=o.text??o.value??"";return /^\d{4}$/.test(r)?(e.consume(),Number(r)):null}};var $c=new Set(["q1","q2","q3","q4"]),Wc=new Set(["january","jan","february","feb","march","mar","april","apr","may","june","jun","july","jul","august","aug","september","sep","sept","october","oct","november","nov","december","dec"]);function Yc(t){if(t===void 0)return false;if(t.type==="DATETIME_LITERAL")return true;let e=(t.text??t.value??"").toLowerCase();return t.type==="IDENT"||t.type==="UNIT"?$c.has(e)||Wc.has(e):t.type==="NUMBER"&&/^\d{4}$/.test(t.text??"")}function Ns(t=60){return {name:"datetime:days-in-period",priority:t,shape:[{types:["UNIT","IDENT"],values:["days"]},{types:["IN"]}],match(e,o){let r=e[o];return r===void 0||(r.text??r.value??"").toLowerCase()!=="days"||r.type!=="UNIT"&&r.type!=="IDENT"||e[o+1]?.type!=="IN"||!Yc(e[o+2])?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("DAYS_IN_PERIOD","days in",[r,e[o+1]])],ruleName:"datetime:days-in-period"}}}}function ys(){return {name:"datetime:daily-note-link",priority:80,shape:[{types:["LBRACKET"]},{types:["LBRACKET"]}],match(t,e){return t[e]?.type!=="LBRACKET"||t[e+1]?.type!=="LBRACKET"||t[e+2]?.type!==chunk7RC6RBS6_cjs.o||t[e+3]?.type!=="RBRACKET"||t[e+4]?.type!=="RBRACKET"?null:{consumed:5,replacement:[t[e+2]],ruleName:"datetime:daily-note-link"}}}}var En={name:"solve-datetime",phrases:{"workdays in":"WORKDAYS_IN","working days after":"WORKDAYS_AFTER","business days after":"WORKDAYS_AFTER","working day after":"WORKDAYS_AFTER","business day after":"WORKDAYS_AFTER","working days from":"WORKDAYS_AFTER","business days from":"WORKDAYS_AFTER","working day from":"WORKDAYS_AFTER","business day from":"WORKDAYS_AFTER","working days before":"WORKDAYS_BEFORE","business days before":"WORKDAYS_BEFORE","working day before":"WORKDAYS_BEFORE","business day before":"WORKDAYS_BEFORE","working days between":"WORKDAYS_BETWEEN","business days between":"WORKDAYS_BETWEEN","day of the week on":"WEEKDAY_ON","weekday on":"WEEKDAY_ON","current timestamp":"CURRENT_TIMESTAMP","to date":"TO_DATE","to timestamp":"TO_TIMESTAMP","what day is it":"WEEKDAY_ON","what day is it on":"WEEKDAY_ON","what day will it be on":"WEEKDAY_ON","what day is it in":"WEEKDAY_IN","what day will it be in":"WEEKDAY_IN","what month is it":"MONTH_ON","what month is it on":"MONTH_ON","month of":"MONTH_ON","what month is it in":"MONTH_IN","what month will it be in":"MONTH_IN","what week is it":"WEEK_ON","what week is it on":"WEEK_ON","week of":"WEEK_ON","week number on":"WEEK_ON","week number of":"WEEK_ON","week number":"WEEK_ON","what week is it in":"WEEK_IN","what week will it be in":"WEEK_IN","is a weekend":"IS_WEEKEND","is on a weekend":"IS_WEEKEND","is a workday":"IS_WORKDAY","is a weekday":"IS_WORKDAY","is a business day":"IS_WORKDAY","age of":"AGE_OF","next month":"MONTH_ANCHOR_NEXT","this month":"MONTH_ANCHOR_THIS","last month":"MONTH_ANCHOR_LAST"},prefixParselets:{DAYS_IN_PERIOD:new Zt,NOW:new de(0),TODAY:new de(0),TOMORROW:new de(1),YESTERDAY:new de(-1),NEXT:new nt("next"),LAST:new nt("last"),UNTIL_UNIT:new it("until"),SINCE_UNIT:new it("since"),WORKDAYS_IN:new Ft,WORKDAYS_BETWEEN:new Ht,WEEKDAY_ON:new ee("weekdayOnDate","on"),WEEKDAY_IN:new ee("weekdayOnDate","in"),MONTH_ON:new ee("monthOnDate","on"),MONTH_IN:new ee("monthOnDate","in"),WEEK_ON:new ee("weekOnDate","on"),WEEK_IN:new ee("weekOnDate","in"),BETWEEN_UNIT:new Gt,CURRENT_TIMESTAMP:new zt,DATETIME_LITERAL:new Wt,DATETIME_LITERAL_UNREADABLE:new Yt,NTH_WEEKDAY:new jt,AGE_OF:new Xt,MONTH_ANCHOR_NEXT:new Le(1),MONTH_ANCHOR_THIS:new Le(0),MONTH_ANCHOR_LAST:new Le(-1)},infixParselets:{WORKDAYS_AFTER:new at("forward"),WORKDAYS_BEFORE:new at("backward"),TO_DATE:new Kt,TO_TIMESTAMP:new $t,IS_WEEKEND:new st("isWeekendOnDate"),IS_WORKDAY:new st("isWorkdayOnDate")},normalizerRules:[ds(),Es(),Ts(),fs(),Ns(),ys()],pluginFunctions:{workdaysInDuration:Xa,weekdayOnDate:pn,toDateFromAny:Ja,toTimestampFromAny:es,datetimeLiteralGrain:ts,monthOnDate:fn,weekOnDate:dn,isWeekendOnDate:Qa,isWorkdayOnDate:qa,spanBetweenDates:Za,nthWeekdayOfMonth:ms,monthAnchorShift:ls,ageBetween:us,dateLiteralFault:cs},asConverters:{iso8601:(t,e)=>chunkGJZIJK2Q_cjs.t(chunk7RC6RBS6_cjs.e(t.toNumber(),chunkTPPM4QSS_cjs.c(e))),weekday:(t,e)=>pn([t],e),month:(t,e)=>fn([t],e),week:(t,e)=>dn([t],e)},tokenCategories:{NTH_WEEKDAY:"datetime",MONTH_ANCHOR_NEXT:"datetime",MONTH_ANCHOR_THIS:"datetime",MONTH_ANCHOR_LAST:"datetime",AGE_OF:"keyword",DATETIME_LITERAL_UNREADABLE:"datetime"}};function Tn(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let r=chunkE4HAKNBQ_cjs.h(e)*6e4;return o.formatTimeInZone("UTC",t+r)}return o.formatTimeInZone(e,t)}function Ps(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let r=chunkE4HAKNBQ_cjs.h(e)*6e4;return o.formatDateInZone("UTC",t+r)}return o.formatDateInZone(e,t)}function gs(t,e,o){if(chunkE4HAKNBQ_cjs.g(e)){let n=chunkE4HAKNBQ_cjs.d(t+chunkE4HAKNBQ_cjs.h(e)*6e4);return {year:n.year,month0:n.month0,day:n.day}}let r=o.fieldsInZone(e,t);return {year:r.year,month0:r.month0,day:r.day}}function _s(t,e,o,r){let n=gs(t,e,r),i=gs(t,o,r),a=chunkE4HAKNBQ_cjs.a(n.year,n.month0,n.day),s=chunkE4HAKNBQ_cjs.a(i.year,i.month0,i.day);return Math.round((a-s)/864e5)}function Nn(t){if(chunkE4HAKNBQ_cjs.g(t)){let o=chunkE4HAKNBQ_cjs.h(t),r=o>=0?"+":"-",n=Math.abs(o),i=Math.floor(n/60),a=n%60;return a===0?`UTC${r}${i}`:`UTC${r}${i}:${String(a).padStart(2,"0")}`}return (t.split("/").pop()??t).replace(/_/g," ")}function me(t){let e=t.peek();if(!e)return null;let o=e.value,r=o.toLowerCase();if(r==="gmt"||r==="utc"){t.consume();let i=t.peek();if(i?.type==="PLUS"||i?.type==="MINUS"){let s=i.type==="MINUS";t.consume();let l=t.peek(),u;if(l?.type==="CLOCK_TIME")t.consume(),u=parseInt(l.value,10);else {let f=t.consume("NUMBER");if(u=parseInt(f.value,10)*60,t.peek()?.type==="COLON"){t.consume();let T=t.consume("NUMBER");u+=parseInt(T.value,10);}}let c=chunkE4HAKNBQ_cjs.f(s?-u:u);return {zoneRef:c,displayName:Nn(c)}}let a=chunkE4HAKNBQ_cjs.f(0);return {zoneRef:a,displayName:Nn(a)}}let n=chunkQQHHZPEW_cjs.M[r];if(n){t.consume();let i=o.replace(/\b\w/g,a=>a.toUpperCase());return {zoneRef:n,displayName:i}}return null}var Jt="zoneConvert",yn="timeInZone",gn="dateInZone",er="timeDifference";function As(t,e){let o=t[0].toNumber(),r=t[1].value,n=t[2].value,i=chunkTPPM4QSS_cjs.c(e),a=i.fields(i.now()),s=chunkE4HAKNBQ_cjs.j(a.year,a.month0,a.day,Math.floor(o/60),o%60,r,i),l=Tn(s,n,i),u=_s(s,n,r,i);if(u===0)return chunkGJZIJK2Q_cjs.t(l);let c=u>0?"+":"";return chunkGJZIJK2Q_cjs.t(`${l} (${c}${u} day${Math.abs(u)===1?"":"s"})`)}function xs(t,e){let o=t[0].value,r=chunkTPPM4QSS_cjs.c(e);return chunkGJZIJK2Q_cjs.t(Tn(r.now(),o,r))}function Rs(t,e){let o=t[0].value,r=chunkTPPM4QSS_cjs.c(e);return chunkGJZIJK2Q_cjs.t(Ps(r.now(),o,r))}function Os(t,e){let o=t[0].value,r=t[1].value,n=t[2].value,i=t[3].value,a=chunkTPPM4QSS_cjs.c(e),s=a.now(),l=chunkE4HAKNBQ_cjs.i(o,s,a),c=chunkE4HAKNBQ_cjs.i(r,s,a)-l;if(c===0)return chunkGJZIJK2Q_cjs.t(`${i} and ${n} currently share the same UTC offset`);let f=c>0?i:n,T=c>0?n:i,N=Math.abs(c),E=Math.floor(N/60),P=N%60,R=[];return E>0&&R.push(`${E} hour${E===1?"":"s"}`),P>0&&R.push(`${P} minute${P===1?"":"s"}`),chunkGJZIJK2Q_cjs.t(`${f} is ${R.join(" ")} ahead of ${T}`)}var tr=class{constructor(){this.category="Time";}parse(e,o,r){let n=parseInt(o.value,10),i=me(e);if(i!==null){if(e.peek()?.type!=="IN")throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_IN",`Expected "in <city>" after the zone name (e.g. "6pm Sydney in Chicago") but got ${e.peek()?`"${e.peek().value}"`:"end of input"}`);e.consume();let a=me(e);if(a===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_TARGET",'Expected a city or zone name after "in" (e.g. "6pm Sydney in Chicago")');r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(13),r.emitString(i.zoneRef),r.emitOpcode(13),r.emitString(a.zoneRef),r.emitPluginCall(Jt,3);return}r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(120);}};var rr=class{constructor(){this.category="Time";}parse(e,o,r){let[n,i]=o.value.split(":"),a=parseInt(n,10),s=parseInt(i,10),l=s>=a?s-a:1440-a+s;r.emitOpcode(10),r.emitNumber(l),r.emitOpcode(13),r.emitString("minutes"),r.emitOpcode(80);}};var or=class{constructor(){this.category="Time";}parse(e,o,r){r.emitOpcode(10),r.emitNumber(parseFloat(o.value)),r.emitOpcode(13),r.emitString("frames/s"),r.emitOpcode(80);}};var nr=class{constructor(){this.category="Time";}parse(e,o,r){r.emitOpcode(10),r.emitNumber(parseFloat(o.value)),r.emitOpcode(13),r.emitString("s"),r.emitOpcode(80);}};function Pn(t){return {category:"Time",parse(e,o,r){let n=me(e);if(n===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_ZONE_EXPECTED_CITY",`Expected a city or zone name after "${o.value}" (e.g. "time in Paris")`);r.emitOpcode(13),r.emitString(n.zoneRef),r.emitPluginCall(t,1);}}}var ir=class{constructor(){this.category="Time";}parse(e,o,r){let n=me(e);if(n===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_DIFFERENCE_EXPECTED_CITY",'Expected a city or zone name after "time difference between" (e.g. "time difference between Seattle and Moscow")');e.consume("AND_CONJ");let i=me(e);if(i===null)throw chunkGXO7TSXQ_cjs.c.parsing("TIME_DIFFERENCE_EXPECTED_SECOND_CITY",'Expected a second city or zone name after "and" (e.g. "time difference between Seattle and Moscow")');r.emitOpcode(13),r.emitString(n.zoneRef),r.emitOpcode(13),r.emitString(i.zoneRef),r.emitOpcode(13),r.emitString(n.displayName),r.emitOpcode(13),r.emitString(i.displayName),r.emitPluginCall(er,4);}};var ar=class{constructor(){this.category="Time";}parse(e,o,r){let[n,i,a,s]=o.value.split(",").map(Number),l=e.peek();if(!l||l.type!=="RATE_AT"&&l.type!=="AT")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`A video timecode must specify a frame rate, e.g. "${o.value.split(",").join(":")} at 30 fps" or "... @ 30 fps"`);e.consume();let u=e.peek();if(!u||u.type!=="FPS_RATE")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`Expected "<number> fps" after "${l.value}" (e.g. "at 30 fps")`);e.consume();let c=parseFloat(u.value),f=Math.round(c);if(s>=f)throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_FRAME_OUT_OF_RANGE",`Frame number ${s} is out of range for ${c} fps (must be 0-${f-1})`);let T=(n*3600+i*60+a)*f+s,N=chunkGJZIJK2Q_cjs.z(c);if(e.peek()?.type==="IN"){e.consume();let E=e.peek();if(!E||E.type!=="IDENT"||E.value.toLowerCase()!=="frames")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FRAMES",`Expected "frames" after "in" (e.g. "... in frames") but got ${E?`"${E.value}"`:"end of input"}`);e.consume(),N="frames";}r.emitOpcode(10),r.emitNumber(T),r.emitOpcode(13),r.emitString(N),r.emitOpcode(80);}};function Cs(t,e){let o=Math.max(1,Math.round(e)),r=c=>String(c).padStart(2,"0"),n=Math.trunc(t),i=(n%o+o)%o,a=Math.floor(n/o),s=Math.floor(a/3600),l=Math.floor(a%3600/60),u=a%60;return `${r(s)}:${r(l)}:${r(u)}:${r(i)}`}var sr=class{constructor(){this.category="Time";}parse(e,o,r){let n=parseFloat(o.value),i=e.peek();if(i&&(i.type==="RATE_AT"||i.type==="AT")){e.consume();let a=e.peek();if(!a||a.type!=="FPS_RATE")throw chunkGXO7TSXQ_cjs.c.parsing("TIMECODE_EXPECTED_FPS",`Expected "<number> fps" after "${i.value}" (e.g. "@ 30 fps")`);e.consume();let s=parseFloat(a.value);r.emitOpcode(13),r.emitString(Cs(n,s));return}r.emitOpcode(10),r.emitNumber(n),r.emitOpcode(13),r.emitString("frames"),r.emitOpcode(80);}};function Is(t,e,o){if(e<0||e>59)return null;if(o){if(t<1||t>12)return null;let r=o.toLowerCase()==="pm";return (t%12+(r?12:0))*60+e}return t<0||t>23?null:t*60+e}function hs(t){return !!t&&t.type==="IDENT"&&/^(am|pm)$/i.test(t.value)}function Ss(t=65){return {name:"time:clock-time",priority:t,shape:[{types:["NUMBER"]},{types:["COLON","IDENT"]}],match(e,o){let r=e[o];if(r.type!=="NUMBER")return null;let n=parseInt(r.value,10);if(isNaN(n)||n<0||n>23||chunkZSLVLMO5_cjs.e(e,o))return null;let i=e[o+1],a=e[o+2];if(i?.type==="COLON"&&a?.type==="NUMBER"){let l=parseInt(a.value,10),u=e[o+3],c=hs(u),f=Is(n,l,c?u.value:void 0);if(f===null)return null;let T=c?4:3;return {consumed:T,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME",String(f),e.slice(o,o+T))],ruleName:"time:clock-time"}}let s=e[o+1];if(hs(s)){let l=Is(n,0,s.value);return l===null?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME",String(l),e.slice(o,o+2))],ruleName:"time:clock-time"}}return null}}}function Ls(t=66){return {name:"time:clock-time-interval",priority:t,shape:[{types:["CLOCK_TIME"]},{types:["TO"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];return r.type!=="CLOCK_TIME"||n?.type!=="TO"||i?.type!=="CLOCK_TIME"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("CLOCK_TIME_INTERVAL",`${r.value}:${i.value}`,e.slice(o,o+3))],ruleName:"time:clock-time-interval"}}}}function vs(t=65){return {name:"time:fps-rate",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["fps"]}],match(e,o){let r=e[o],n=e[o+1];return r.type!=="NUMBER"||n?.type!=="IDENT"||n.value.toLowerCase()!=="fps"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("FPS_RATE",r.value,e.slice(o,o+2))],ruleName:"time:fps-rate"}}}}function ks(t=70){return {name:"time:laptime",priority:t,shape:[{types:["NUMBER"]},{types:["COLON"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2],a=e[o+3],s=e[o+4];if(r.type!=="NUMBER"||n?.type!=="COLON"||i?.type!=="NUMBER"||a?.type!=="COLON"||s?.type!=="NUMBER"||chunkZSLVLMO5_cjs.e(e,o))return null;let l=parseInt(r.value,10),u=parseInt(i.value,10),c=parseFloat(s.value);if(isNaN(l)||isNaN(u)||isNaN(c)||u<0||u>59||c<0||c>=60)return null;let f=l*3600+u*60+c;return {consumed:5,replacement:[chunkZSLVLMO5_cjs.b("LAPTIME",String(f),e.slice(o,o+5))],ruleName:"time:laptime"}}}}function ws(t=75){return {name:"time:video-timecode",priority:t,shape:[{types:["NUMBER"]},{types:["COLON"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2],a=e[o+3],s=e[o+4],l=e[o+5],u=e[o+6];if(r?.type!=="NUMBER"||n?.type!=="COLON"||i?.type!=="NUMBER"||a?.type!=="COLON"||s?.type!=="NUMBER"||l?.type!=="COLON"||u?.type!=="NUMBER"||chunkZSLVLMO5_cjs.e(e,o))return null;let c=parseInt(r.value,10),f=parseInt(i.value,10),T=parseInt(s.value,10),N=parseInt(u.value,10);return [c,f,T,N].some(E=>isNaN(E))||f<0||f>59||T<0||T>59||c<0||N<0?null:{consumed:7,replacement:[chunkZSLVLMO5_cjs.b("VIDEO_TIMECODE",`${c},${f},${T},${N}`,e.slice(o,o+7))],ruleName:"time:video-timecode"}}}}function Ms(t=65){return {name:"time:frame-count",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["frames"]}],match(e,o){let r=e[o],n=e[o+1];return r.type!=="NUMBER"||n?.type!=="IDENT"||n.value.toLowerCase()!=="frames"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("FRAME_COUNT",r.value,e.slice(o,o+2))],ruleName:"time:frame-count"}}}}var jc=14,Xc=[["week","weeks",604800],["day","days",86400],["hour","hours",3600],["minute","minutes",60],["second","seconds",1]];function Bs(t){if(t.type===0)return t.toNumber();if(t.type!==6||t.unit===void 0)return null;let e=chunkEZKR44MA_cjs.a[t.unit.toLowerCase()];return e===void 0||e[0]!==jc?null:t.toNumber()*e[1]}function Us(t){let e=Bs(t);if(e===null)return chunkGJZIJK2Q_cjs.t(`"as timespan" needs a duration, got ${t.unit??"a non-duration"}`);let o=e<0,r=Math.abs(e),n=[];for(let[a,s,l]of Xc){if(l===1)break;let u=Math.floor(r/l);u>0&&(n.push(`${u} ${u===1?a:s}`),r-=u*l);}let i=Math.round(r*1e3)/1e3;return (i>0||n.length===0)&&n.push(`${i} ${i===1?"second":"seconds"}`),chunkGJZIJK2Q_cjs.t((o?"-":"")+n.join(" "))}function An(t){let e=Bs(t);if(e===null)return chunkGJZIJK2Q_cjs.t(`"as laptime" needs a duration, got ${t.unit??"a non-duration"}`);let o=e<0,r=Math.round(Math.abs(e)*1e3)/1e3,n=Math.floor(r/3600),i=Math.floor(r%3600/60),a=r%60,s=Math.floor(a),l=Math.round((a-s)*1e3),u=`${_n(n)}:${_n(i)}:${_n(s)}`;return chunkGJZIJK2Q_cjs.t((o?"-":"")+(l>0?`${u}.${String(l).padStart(3,"0")}`:u))}function _n(t){return t<10?`0${t}`:String(t)}var xn={name:"solve-time",asConverters:{timespan:Us,laptime:An,lap:An},phrases:{"time in":"TIME_IN","date in":"DATE_IN","time difference between":"TIME_DIFFERENCE_BETWEEN",...Object.fromEntries(Object.keys(chunkQQHHZPEW_cjs.L).map(t=>[t,"CITY_NAME"]))},prefixParselets:{CLOCK_TIME:new tr,CLOCK_TIME_INTERVAL:new rr,FPS_RATE:new or,LAPTIME:new nr,TIME_IN:Pn(yn),DATE_IN:Pn(gn),TIME_DIFFERENCE_BETWEEN:new ir,VIDEO_TIMECODE:new ar,FRAME_COUNT:new sr},normalizerRules:[Ss(),Ls(),vs(),ks(),ws(),Ms()],pluginFunctions:{[Jt]:As,[yn]:xs,[gn]:Rs,[er]:Os}};function mr(t){for(let e of t.alternatives){let o=e.slots[0];if(!o||o.kind!=="keyword")throw chunkGXO7TSXQ_cjs.c.config("INVALID_PHRASE_PATTERN","Every PhraseAlternative's first slot must be a `keyword` slot \u2014 alternatives are chosen by peeking the next token, which only works if the choice is decidable from one leading keyword.",{category:t.category})}return {category:t.category,parse(e,o,r){let n=e.peek(),i=t.alternatives.find(s=>{let l=s.slots[0];return n!==void 0&&l.tokenTypes.includes(n.type)});if(!i){let s=t.alternatives.map(l=>l.slots[0].tokenTypes.join("|")).join(", ");throw chunkGXO7TSXQ_cjs.c.parsing("NO_MATCHING_PHRASE_ALTERNATIVE",`Expected one of [${s}] but got "${n?.type??"end of input"}" ("${n?.value??""}")`,{category:t.category,expected:s,actualType:n?.type,actualValue:n?.value})}let a=[];for(let s of i.slots)if(s.kind==="keyword"){let l=e.peek();if(!l||!s.tokenTypes.includes(l.type))throw chunkGXO7TSXQ_cjs.c.parsing("PHRASE_KEYWORD_MISMATCH",`Expected one of [${s.tokenTypes.join("|")}] but got "${l?.type??"end of input"}" ("${l?.value??""}")`,{category:t.category,expected:s.tokenTypes,actualType:l?.type,actualValue:l?.value});e.consume(),a.push({type:l.type,value:l.value});}else e.parseExpression(s.bindingPower??0,r);i.emit(r,a);}}}var Qc=37;function lr(t){t.emitOpcode(51),t.emitIndex(Qc),t.emitIndex(2);}var qc=mr({category:"Dice",alternatives:[{slots:[{kind:"keyword",tokenTypes:["BETWEEN"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["AND_CONJ"]},{kind:"expr"}],emit:lr},{slots:[{kind:"keyword",tokenTypes:["FROM"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["TO"]},{kind:"expr"}],emit:lr},{slots:[{kind:"keyword",tokenTypes:["LPAREN"]},{kind:"expr"},{kind:"keyword",tokenTypes:["COMMA"]},{kind:"expr"},{kind:"keyword",tokenTypes:["RPAREN"]}],emit:lr}]}),ur=class{constructor(){this.category="Dice";}parse(e,o,r){let n=e.peek();if(n&&n.type==="NUMBER"){let i=e.consume();r.emitOpcode(10),r.emitNumber(parseFloat(i.value)),e.consume("MINUS");let a=e.consume();r.emitOpcode(10),r.emitNumber(parseFloat(a.value)),lr(r);return}qc.parse(e,o,r);}};var Rn={name:"solve-dice",prefixParselets:{ROLL:new ur}};var cr=class{constructor(){this.category="Variable";}parse(e,o,r){let n=e.consume();if(n.type!=="IDENT"&&n.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("EXPECTED_IDENTIFIER",`Expected identifier or unit after colon, got ${n.type}`,{tokenType:n.type});let i=n.value;e.peek()?.type==="EQUALS"?(e.consume("EQUALS"),e.parseExpression(0,r),r.emitOpcode(61),r.emitString(i)):(r.emitOpcode(60),r.emitString(i));}};var lt=class{constructor(){this.category="Variable";}parse(e,o,r){r.emitOpcode(60),r.emitString(o.value);}};var pr=class{constructor(){this.category="Variable";}parse(e,o,r){e.consume("COLON");let n=e.consume();if(n.type!=="IDENT"&&n.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("EXPECTED_IDENTIFIER",`Expected identifier after 'global :', got ${n.type}`,{tokenType:n.type});let i=n.value;e.peek()?.type==="EQUALS"?(e.consume("EQUALS"),e.parseExpression(0,r),r.emitOpcode(63),r.emitString(i)):(r.emitOpcode(62),r.emitString(i));}};var fr=class{constructor(){this.namespace="global-variables";this.local=true;this.pending=new Map;}preflight(e,o,r,n,i){let{opcodes:a,strings:s}=o,l=a.length,u=0;for(;u<l;){if(a[u]===62){let f=s[a[u+1]];if(!chunkQQHHZPEW_cjs.J.has(f))return this.pendingResultFor(f,r,n)}u=chunkG2V33LFM_cjs.a(a,u);}return null}pendingResultFor(e,o,r){let n=this.pending.get(e);return n||(n=new Promise(i=>{let a=chunkQQHHZPEW_cjs.J.subscribe((s,l)=>{s===e&&(a(),this.pending.delete(e),i(l));});}),this.pending.set(e,n)),{queryKey:`global:${e}`,resolver:n,packageId:o,signal:r,metadata:{varName:e}}}destroy(){this.pending.clear();}};var On={name:"solve-variables",asyncResolvers:[new fr],prefixParselets:{COLON:new cr,IDENT:new lt,UNIT:new lt,GLOBAL:new pr}};var bs="currency-historical",Ee="historicalCurrency",Zc=`solve-currency:${Ee}`,dr={NOT_CONFIGURED:"HISTORICAL_RATES_NOT_CONFIGURED",QUERY_FAILED:"HISTORICAL_RATE_QUERY_FAILED",NOT_PREFLIGHTED:"HISTORICAL_RATE_NOT_PREFLIGHTED",INVALID_OPERAND:"HISTORICAL_CURRENCY_INVALID_OPERAND"},Jc=3e4,Vs=1/0,ep=1e4;function Cn(t,e,o){return [bs,`${t.toUpperCase()}:${e.toUpperCase()}:${o}`]}function Ds(t){return t<10?`0${t}`:String(t)}function Er(t,e,o){if(!chunkTMQ37JQY_cjs.c.isCurrency(e)||o!==void 0&&!chunkTMQ37JQY_cjs.c.isCurrency(o))return null;let r=t.peek();if(!r||r.type!=="IDENT"||r.value.toLowerCase()!=="on")return null;let n=t.peekAt(1);if(!n||n.type!=="DATETIME_LITERAL")return null;t.consume(),t.consume();let i=t.getCalendar().fields(Number(n.value));return `${i.year}-${Ds(i.month0+1)}-${Ds(i.day)}`}async function Fs(t,e,o,r,n,i){let a=e.toUpperCase(),s=o.toUpperCase();if(!t)return chunkGJZIJK2Q_cjs.P(dr.NOT_CONFIGURED,`Historical exchange rates are not configured. Supply historicalRateProvider via createCurrencyPackage({ ... }) to convert ${a} to ${s} on ${r}.`);let{signal:l,cleanup:u}=chunkTLG7VZRX_cjs.a(n,ep,"Historical currency rate fetch");try{let c=await t(a,s,r,l);return chunkGJZIJK2Q_cjs.n(c)}catch(c){let f=chunkGJZIJK2Q_cjs.P(dr.QUERY_FAILED,`Failed to resolve the historical rate for ${a} to ${s} on ${r}: ${c instanceof Error?c.message:String(c)}`),T=Cn(e,o,r);return setTimeout(()=>{i.getQueryData(T)===f&&i.removeQueries({queryKey:T,exact:true});},Jc).unref?.(),f}finally{u();}}function In(t){return e=>{let o=e[0],r=e[1],n=e[2],i=chunkGJZIJK2Q_cjs.Q(o);if(i)return i;if(o.type!==6||o.unit===void 0||!chunkTMQ37JQY_cjs.c.isCurrency(o.unit))return chunkGJZIJK2Q_cjs.P(dr.INVALID_OPERAND,'Historical conversion needs an amount in a currency, for example "100 USD in GBP on 2024-01-15".');let a=o.unit,s=String(r.value),l=String(n.value);if(a.toUpperCase()===s.toUpperCase())return chunkGJZIJK2Q_cjs.u(o.toNumber(),s);let u=chunkZLRJ7TDP_cjs.b(),c=Cn(a,s,l),f=u?.getQueryData(c);if(f===void 0)return u?u.fetchQuery({queryKey:c,queryFn:({signal:N})=>Fs(t,a,s,l,N,u),staleTime:Vs}):chunkGJZIJK2Q_cjs.P(dr.NOT_PREFLIGHTED,`No historical rate resolved for ${a.toUpperCase()} to ${s.toUpperCase()} on ${l}.`);if(f.type===13)return f;let T=f.value;return chunkGJZIJK2Q_cjs.u(o.toNumber()*T,s)}}function Hs(t){return {namespace:bs,preflight(e,o,r,n,i){let{opcodes:a,strings:s}=o,l=a.length,u=chunkQQHHZPEW_cjs.F(Zc),c=0,f=[];for(;c<l;){let T=a[c];if(T===13)f.push(a[c+1]);else if(T===50){let N=a[c+1],E=a[c+2];if(N===u&&E===3&&f.length>=3){let P=s[f[f.length-1]],R=s[f[f.length-2]],O=new Set;for(let g=0;g<f.length-2;g++){let A=s[f[g]];chunkTMQ37JQY_cjs.c.isCurrency(A)&&O.add(A.toUpperCase());}if(O.size===1){let g=O.values().next().value;if(g!==R.toUpperCase()){let A=Cn(g,R,P);if(i.getQueryData(A)===void 0){let S=i.fetchQuery({queryKey:A,queryFn:({signal:v})=>Fs(t,g,R,P,v,i),staleTime:Vs});return {queryKey:A.join(":"),resolver:S,packageId:r,signal:n,metadata:{from:g,to:R,isoDate:P}}}}}}f=[];}c=chunkG2V33LFM_cjs.a(a,c);}return null},destroy(){}}}function Gs(t){return chunkFDKTESBC_cjs.ta(t)??t}var Tr=class{constructor(){this.category="UoM";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){let i=Gs(r.value);if(n.emitOpcode(13),n.emitString(i),!(e.infixMinBindingPower>=chunkZDJTDFTR_cjs.a.Product)&&(e.peek()?.type==="TO"||e.peek()?.type==="IN")){e.consume();let s=e.peek();if(s?.type==="UNIT"||s?.type==="IN"){e.consume();let l=Gs(s.value),u=Er(e,l,i);if(u!==null){n.emitOpcode(80),n.emitOpcode(13),n.emitString(l),n.emitOpcode(13),n.emitString(u),n.emitPluginCall(Ee,3);return}n.emitOpcode(13),n.emitString(l),n.emitOpcode(81);return}if(s?.type==="QUESTION"){e.consume(),n.emitOpcode(85);return}}if(e.peek()?.type==="BEST"){e.consume(),n.emitOpcode(83);return}n.emitOpcode(80);}};function hn(t){return chunkFDKTESBC_cjs.ta(t)??t}var Nr=class{constructor(){this.category="UoM";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Postfix,r);let n=e.peek();if(n&&n.type==="UNIT"){if(e.consume(),r.emitOpcode(13),r.emitString(hn(n.value)),e.peek()?.type==="TO"){e.consume("TO");let i=e.consume();i?.type==="UNIT"?(r.emitOpcode(13),r.emitString(hn(i.value)),r.emitOpcode(81)):i?.type==="BEST"&&r.emitOpcode(83);}else r.emitOpcode(80);return}if(n&&(n.type==="TO"||n.type==="IN")){e.consume();let i=e.peek();i?.type==="UNIT"||i?.type==="IN"||i?.type==="DOLLAR"||i?.type==="POUND"||i?.type==="EURO"||i?.type==="YEN"||i?.type==="RUBLE"||i?.type==="WON"||i?.type==="CURRENCY_SYMBOL"||i?.type==="IDENT"?(e.consume(),r.emitOpcode(13),r.emitString(hn(i.value)),r.emitOpcode(84)):i?.type==="BEST"&&(e.consume(),r.emitOpcode(83));return}}};var yr=class{constructor(){this.category="UoM";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitOpcode(85);}};function zs(t=60){return {name:"uom:possibilities",priority:t,shape:[{types:["UNIT"]},{types:["TO"]}],match(e,o){if(o+2>=e.length)return null;let r=e[o],n=e[o+1],i=e[o+2];return r.type!=="UNIT"||n.type!=="TO"||i.type!=="QUESTION"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("UOM_POSSIBILITIES_QUERY",r.value,[r,n,i])],ruleName:"uom:possibilities"}}}}var Ks=14;function $s(t,e){if(t===void 0||t.type!=="UNIT")return;let o=(t.value??"").toLowerCase();if(o==="m"&&e===Ks)return {kind:Ks,ratio:60,spelling:"minutes"};let r=chunkEZKR44MA_cjs.a[o];return r===void 0?void 0:{kind:r[0],ratio:r[1],spelling:o}}var Ws=/^\d+(\.\d+)?$/;function Ys(t=63){return {name:"uom:compound-quantity",priority:t,shape:[{types:["NUMBER"]},{types:["UNIT"]}],match(e,o){let r=e[o];if(r?.type!=="NUMBER"||!Ws.test(r.text??""))return null;let n=$s(e[o+1]);if(n===void 0)return null;let i=n.kind,a=n.ratio,s=Number(r.text)*a,l=n.spelling,u=e[o+1],c=2;for(;;){let N=e[o+c];if(N?.type!=="NUMBER"||!Ws.test(N.text??""))break;let E=$s(e[o+c+1],i);if(E===void 0||E.kind!==i||E.ratio>=a)break;s+=Number(N.text)*E.ratio,a=E.ratio,l=E.spelling,u=e[o+c+1],c+=2;}if(c===2)return null;let f=e.slice(o,o+c),T=s/a;return {consumed:c,replacement:[chunkZSLVLMO5_cjs.b("NUMBER",String(T),f),chunkZSLVLMO5_cjs.b("UNIT",l,[u])],ruleName:"uom:compound-quantity"}}}}function js(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}function Xs(t=59){return {name:"uom:two-unit-conversion",priority:t,shape:[{types:["IN","TO"]},{types:["UNIT"]}],match(e,o){let r=e[o];if(r?.type!=="IN"&&r?.type!=="TO"||!js(e[o+1])||e[o+2]?.type!=="AND_CONJ"||!js(e[o+3]))return null;let n=e[o+1].value,i=e[o+3].value;return {consumed:4,replacement:[chunkZSLVLMO5_cjs.b("IN_TWO_UNITS",`${n} ${i}`,e.slice(o,o+4))],ruleName:"uom:two-unit-conversion"}}}}function Qs(t=74){return {name:"uom:degree-symbol",priority:t,shape:[{types:["NUMBER"]},{types:["IDENT"],values:["\xB0"]}],match(e,o){let r=e[o];if(r?.type!=="NUMBER")return null;let n=e[o+1];return n===void 0||n.type!=="IDENT"||(n.text??n.value??"")!=="\xB0"?null:{consumed:2,replacement:[r,chunkZSLVLMO5_cjs.b("UNIT","degrees",[n])],ruleName:"uom:degree-symbol"}}}}var gr=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let[i,a]=String(r.value).split(" ");n.emitOpcode(13),n.emitString(i),n.emitOpcode(13),n.emitString(a),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(3);}};function qs(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var Sn=new Set(["per","a","an","each","every"]);function tp(t){if(t===void 0||t.type!=="IDENT")return false;let e=(t.text??t.value??"").toLowerCase();return Sn.has(e)?false:/^[a-z][a-z_]{2,}$/.test(e)&&chunkEZKR44MA_cjs.a[e]===void 0}function Zs(t=75){return {name:"uom:bare-rate-denominator",priority:t,shape:[{types:["NUMBER","SLASH","IDENT"]},{types:["IDENT","UNIT"]}],match(e,o){let r=e[o];if(r===void 0)return null;if(r.type==="NUMBER"&&tp(e[o+1])){let l=e[o+1],u=e[o+2];if((u?.type==="SLASH"||u?.type==="IDENT"&&Sn.has((u.text??u.value??"").toLowerCase()))&&qs(e[o+3]))return {consumed:2,replacement:[r,chunkZSLVLMO5_cjs.b("UNIT",l.value,[l])],ruleName:"uom:bare-rate-denominator"}}if(!qs(e[o+1]))return null;let n=r.type==="SLASH",i=(r.text??r.value??"").toLowerCase(),a=r.type==="IDENT"&&Sn.has(i);if(!n&&!a)return null;let s=e[o+1];return {consumed:2,replacement:[chunkZSLVLMO5_cjs.b("PER_UNIT",s.value,[r,s])],ruleName:"uom:bare-rate-denominator"}}}}var Pr=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){n.emitOpcode(13),n.emitString(String(r.value)),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};var _r=class{constructor(e){this.builtinIndex=e;this.category="Uom";this.bindingPower=chunkZDJTDFTR_cjs.a.Product;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};function rp(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var op=new Set(["per","a","an","each","every"]);function np(t,e){for(let o=e;o<t.length&&o<e+5;o++){let r=t[o];if(r.type==="PER_UNIT")return true;if(r.type==="EOF"||r.type==="COMMA"||r.type==="RATE_AT")return false;if(r.type==="UNIT"&&chunkZKFCKAIX_cjs.i(r.value??void 0))return true;let n=(r.text??r.value??"").toLowerCase();if((r.type==="SLASH"||r.type==="IDENT"&&op.has(n))&&rp(t[o+1]))return true}return false}function Js(t=73){return {name:"uom:at-rate",priority:t,shape:[{types:["RATE_AT"]}],match(e,o){return e[o]?.type!=="RATE_AT"||!np(e,o+1)?null:{consumed:1,replacement:[chunkZSLVLMO5_cjs.b("AT_RATE","at",[e[o]])],ruleName:"uom:at-rate"}}}}function ip(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var ap=new Set(["a","an"]);function em(t=76){return {name:"uom:for-duration",priority:t,shape:[{types:["FOR_DURATION"]},{types:["IDENT"]}],match(e,o){let r=e[o];if(r?.type!=="FOR_DURATION")return null;let n=e[o+1];return n?.type!=="IDENT"||!ap.has((n.text??n.value??"").toLowerCase())||!ip(e[o+2])?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("STAR","*",[r]),chunkZSLVLMO5_cjs.b("NUMBER","1",[n]),e[o+2]],ruleName:"uom:for-duration"}}}}function Ln(t){return t===void 0||t.type!=="UNIT"?false:chunkEZKR44MA_cjs.a[(t.value??"").toLowerCase()]!==void 0}var sp=new Set(["a","an"]);function tm(t=61){return {name:"uom:reversed-conversion",priority:t,shape:[{types:["UNIT"]},{types:["IN"]}],match(e,o){if(o!==0||!Ln(e[o])||e[o+1]?.type!=="IN")return null;let r=e[o],n=e[o+2];if(n===void 0)return null;if(n.type==="NUMBER"&&Ln(e[o+3]))return {consumed:4,replacement:[n,e[o+3],e[o+1],r],ruleName:"uom:reversed-conversion"};let i=(n.text??n.value??"").toLowerCase();return n.type==="IDENT"&&sp.has(i)&&Ln(e[o+3])?{consumed:4,replacement:[chunkZSLVLMO5_cjs.b("NUMBER","1",[n]),e[o+3],e[o+1],r],ruleName:"uom:reversed-conversion"}:null}}}var mp={water:1,milk:1.03,"whole milk":1.03,"skim milk":1.035,buttermilk:1.03,"heavy cream":1,"whipping cream":1,"sour cream":.96,yogurt:1.03,"greek yogurt":1.05,"cream cheese":1.01,"condensed milk":1.3,"evaporated milk":1.06,"coconut milk":.97,"almond milk":1.03,"soy milk":1.03,butter:.9595,margarine:.96,"vegetable oil":.92,"olive oil":.913,"canola oil":.92,"coconut oil":.92,"sunflower oil":.92,"sesame oil":.92,mayonnaise:.91,sugar:.845,"granulated sugar":.845,"brown sugar":.93,"powdered sugar":.51,"icing sugar":.51,honey:1.42,"maple syrup":1.32,"corn syrup":1.38,molasses:1.4,nutella:1.14,"peanut butter":1.09,flour:.53,"all-purpose flour":.53,"all purpose flour":.53,"bread flour":.54,"cake flour":.47,"whole wheat flour":.55,cornstarch:.53,cornmeal:.65,semolina:.6,rice:.79,"white rice":.79,"brown rice":.8,oats:.34,"rolled oats":.38,breadcrumbs:.43,yeast:.68,"dry yeast":.68,salt:1.2,"table salt":1.2,"kosher salt":.96,"baking powder":.9,"baking soda":.99,"cream of tartar":.68,cinnamon:.56,ginger:.5,"vanilla extract":.88,"lemon juice":1.03,"lime juice":1.02,"orange juice":1.04,vinegar:1.01,cocoa:.41,"cocoa powder":.41,"chocolate chips":.72,"chocolate chunks":.72,coconut:.35,"shredded coconut":.35,raisins:.68,almonds:.55,walnuts:.5,pecans:.5,pistachios:.55,peanuts:.6,"shredded cheese":.4,parmesan:.44,"tomato paste":1.06,"tomato sauce":1.02,ketchup:1.14,broth:1,stock:1,wine:.99,beer:1.01},rm=2;function om(t){return mp[t.toLowerCase().trim()]}var Ar="cookingConvert";function nm(t){let e=t[0],o=t[1].value,r=t[2].value;if(e.type!==6||!e.unit)return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_REQUIRES_UNIT",'Expected a value with a mass or volume unit (e.g. "300g", "10 cups"), got a plain number');let n=e.unit,i=e.toNumber(),a=chunkZKFCKAIX_cjs.c(n),s=chunkZKFCKAIX_cjs.c(r),l=N=>N==="mass"||N==="volume";if(!l(a))return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_UNSUPPORTED_UNIT",`"${n}" is not a recognized mass or volume unit`);if(!l(s))return chunkGJZIJK2Q_cjs.P("COOKING_CONVERSION_UNSUPPORTED_UNIT",`"${r}" is not a recognized mass or volume unit`);if(a===s)return chunkGJZIJK2Q_cjs.u(chunkZKFCKAIX_cjs.e(i,n,r),r);let u=om(o);if(u===void 0)return chunkGJZIJK2Q_cjs.P("COOKING_UNKNOWN_INGREDIENT",`No density data for "${o}" \u2014 cannot convert between mass and volume for this ingredient`);if(a==="mass"){let E=chunkZKFCKAIX_cjs.e(i,n,"g")/u,P=chunkZKFCKAIX_cjs.e(E,"ml",r);return chunkGJZIJK2Q_cjs.u(P,r)}let f=chunkZKFCKAIX_cjs.e(i,n,"ml")*u,T=chunkZKFCKAIX_cjs.e(f,"g",r);return chunkGJZIJK2Q_cjs.u(T,r)}var xr=class{constructor(){this.category="UoM";this.bindingPower=35;}parse(e,o,r,n){let i=r.value;e.consume("IN");let a=e.consume();n.emitOpcode(13),n.emitString(i),n.emitOpcode(13),n.emitString(a.value),n.emitPluginCall(Ar,3);}};function im(t=68){return {name:"uom-cooking:ingredient-name",priority:t,shape:[{types:["IDENT"]}],match(e,o){let r=e[o-1];if(!r||r.type!=="UNIT")return null;for(let n=rm;n>=1;n--){if(o+n>e.length)continue;let i=e.slice(o,o+n);if(!i.every(c=>c.type==="IDENT"))continue;let a=o+n,s=e[a];if(!s||s.type!=="IN")continue;let l=e[a+1];if(!l||l.type!=="UNIT"&&l.type!=="IDENT")continue;let u=i.map(c=>c.value.toLowerCase()).join(" ");return {consumed:n,replacement:[chunkZSLVLMO5_cjs.b("INGREDIENT_NAME",u,i)],ruleName:"uom-cooking:ingredient-name"}}return null}}}function am(t=78){return {name:"uom:multi-word-unit",priority:t,shape:[{types:["UNIT"]},{types:["UNIT"]}],match(e,o){let r=e[o],n=e[o+1];if(r?.type!=="UNIT"||n?.type!=="UNIT"||r.offset+r.text.length+1!==n.offset)return null;let i=`${r.value} ${n.value}`;return chunkEZKR44MA_cjs.a[i]===void 0?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b("UNIT",i,e.slice(o,o+2))],ruleName:"uom:multi-word-unit"}}}}function sm(t=77){return {name:"uom:compound-unit",priority:t,shape:[{types:["UNIT"]},{types:["SLASH"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];if(r?.type!=="UNIT"||n?.type!=="SLASH"||i?.type!=="UNIT")return null;let a=`${r.value}/${i.value}`;return {consumed:3,replacement:[chunkZSLVLMO5_cjs.b("UNIT",a,[r,n,i])],ruleName:"uom:compound-unit"}}}}var vn={name:"solve-uom",prefixParselets:{CONVERT:new Nr,UOM_POSSIBILITIES_QUERY:new yr},infixParselets:{IN_TWO_UNITS:new gr(94),PER_UNIT:new Pr(95),AT_RATE:new _r(96),UNIT:new Tr,INGREDIENT_NAME:new xr},normalizerRules:[am(),sm(),zs(),Ys(),Xs(),Qs(),Js(),em(),Zs(),tm(),im()],pluginFunctions:{[Ar]:nm}};var Z=class{constructor(){this.category="UoM";}parse(e,o,r){let n=chunkFDKTESBC_cjs.ta(o.value)??o.value.toUpperCase();e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),e.peek()?.type==="UNIT"&&e.consume(),r.emitOpcode(13),r.emitString(n),r.emitOpcode(80);}};var Rr=class{constructor(){this.category="UoM";this.bindingPower=35;}parse(e,o,r,n){let i=e.peek();if(i?.type==="IP_CIDR"){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,n),n.emitPluginCall("ipInCidr",2);return}if(i&&(i.type==="UNIT"||i.type==="DOLLAR"||i.type==="POUND"||i.type==="EURO"||i.type==="YEN"||i.type==="RUBLE"||i.type==="WON"||i.type==="CURRENCY_SYMBOL"||i.type==="IDENT"||i.type==="CITY_NAME"||i.type==="IN")){e.consume();let a=chunkFDKTESBC_cjs.ta(i.value)??i.value,s=Er(e,a);if(s!==null){n.emitOpcode(13),n.emitString(a),n.emitOpcode(13),n.emitString(s),n.emitPluginCall(Ee,3);return}n.emitOpcode(13),n.emitString(a),n.emitOpcode(84);}}};function kn(t={}){return {name:"solve-currency",asyncResolvers:[new chunkG2V33LFM_cjs.b,Hs(t.historicalRateProvider)],prefixParselets:{DOLLAR:new Z,POUND:new Z,EURO:new Z,YEN:new Z,RUBLE:new Z,WON:new Z,CURRENCY_SYMBOL:new Z},infixParselets:{IN:new Rr},pluginFunctions:{[Ee]:In(t.historicalRateProvider)}}}var wn=kn();var ve=class{constructor(e=0){this.category="Vector";this.dimension=e;}parse(e,o,r){e.consume("LPAREN");let n=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(0,r),n++;e.match("COMMA");)e.parseExpression(0,r),n++;e.consume("RPAREN"),r.emitOpcode(152),r.emitIndex(1),r.emitIndex(this.dimension>0?this.dimension:n);}};var Or=class{constructor(){this.category="Float";}parse(e,o,r){e.consume("LPAREN"),e.parseExpression(0,r),e.consume("RPAREN"),r.emitOpcode(152),r.emitIndex(1),r.emitIndex(1);}};var Mn={name:"solve-vector",prefixParselets:{VEC2:new ve(2),VEC3:new ve(3),VEC4:new ve(4),FLOAT:new Or}};var Cr=class{constructor(){this.category="Matrix";}parse(e,o,r){let n=0,i=-1;if(e.peek()?.type==="RBRACKET")throw chunkGXO7TSXQ_cjs.c.parsing("EMPTY_MATRIX_LITERAL","A matrix literal cannot be empty \u2014 `[]` has no valid shape.",{});for(;;){let a=0;for(e.parseExpression(0,r),a++;e.match("COMMA");)e.parseExpression(0,r),a++;if(i===-1)i=a;else if(a!==i)throw chunkGXO7TSXQ_cjs.c.parsing("RAGGED_MATRIX_LITERAL",`Matrix literal rows must all have the same number of columns \u2014 row ${n+1} has ${a}, but a previous row has ${i}.`,{expectedCols:i,actualCols:a,row:n+1});if(n++,!e.match("SEMICOLON"))break}e.consume("RBRACKET"),r.emitOpcode(152),r.emitIndex(n),r.emitIndex(i);}};var Ir=class{constructor(){this.category="Matrix";this.bindingPower=chunkZDJTDFTR_cjs.a.Postfix;}parse(e,o,r,n){let i=this.hasTopLevelColon(e);this.parseIndexArg(e,n,i);let a=1;if(e.match("COMMA")&&(this.parseIndexArg(e,n,i),a=2),e.consume("RBRACKET"),!i){a===1?n.emitOpcode(153):n.emitOpcode(154);return}if(a!==2)throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_MATRIX_SLICE_ARITY",`Range-based matrix slicing needs exactly 2 arguments ("a[rowRange, colRange]"), got ${a}.`,{argCount:a});n.emitOpcode(155);}hasTopLevelColon(e){let o=0;for(let r=0;;r++){let n=e.peekAt(r);if(!n)return false;if(n.type==="LBRACKET"||n.type==="LPAREN")o++;else if(n.type==="RBRACKET"||n.type==="RPAREN"){if(o===0)return false;o--;}else if(n.type==="COLON"&&o===0)return true}}parseIndexArg(e,o,r){e.parseExpression(0,o);let n=false;e.match("COLON")&&(e.parseExpression(0,o),n=true),r&&(n||o.emitOpcode(3),o.emitOpcode(156));}};var Bn={name:"solve-matrix",prefixParselets:{LBRACKET:new Cr},infixParselets:{LBRACKET:new Ir}};function hr(t,e){let o=t.peek(),r=t.peekAt(1);if(o&&(o.type==="IDENT"||o.type==="UNIT"||o.type==="FUNC")&&r?.type==="COMMA"){t.consume();let a=o.value,s=un[a.toLowerCase()];return s!==void 0?{kind:1,builtinIdx:s}:{kind:2,name:a}}let n=new chunkZDJTDFTR_cjs.d(e.pluginIndexMap);t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),t.setBuilder(e);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","map/reduce transform expressions must be synchronous (no weather/stocks/currency calls).");return {kind:0,program:i}}function mm(t){let e=t.peek(),o=t.peekAt(1);return !!e&&(e.type==="IDENT"||e.type==="UNIT")&&o?.type==="EQUALS"}function lm(t){let e=t.peek();if(e&&(e.type==="IDENT"||e.type==="UNIT"))return t.consume(),e.value;throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_EXPECTED_COLLECTION_NAME",`Expected a collection name (e.g. "x" in "x=[1,2,3]") but got ${e?`"${e.value}"`:"end of input"}.`)}function te(t,e){t.parseExpression(0,e),t.match("COLON")&&(t.parseExpression(0,e),e.emitOpcode(156));}function le(t,e,o,r,n){if(t.emitOpcode(e),t.emitIndex(o.kind),o.kind===0){let i=t.emitAnonymousBody(r,o.program);t.emitIndex(i);}else o.kind===1?t.emitIndex(o.builtinIdx):t.emitString(o.name);t.emitIndex(n);}var Sr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=hr(e,r);e.consume("COMMA");let i=[];if(mm(e))do{let a=lm(e);e.consume("EQUALS"),te(e,r),i.push(a);}while(e.match("COMMA"));else te(e,r),i.push("x");e.consume("RPAREN"),le(r,157,n,i,i.length);}};var Lr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=hr(e,r);e.consume("COMMA"),te(e,r);let i=0;e.match("COMMA")&&(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i=1),e.consume("RPAREN"),le(r,158,n,["acc","x"],i);}};var vr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);n.emitOpcode(60),n.emitString("acc"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),e.setBuilder(r),n.emitOpcode(20);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","sum's element expression must be synchronous (no weather/stocks/currency calls).");e.consume("COMMA"),te(e,r),e.consume("RPAREN"),r.emitOpcode(10),r.emitNumber(0),le(r,158,{kind:0,program:i},["acc","x"],1);}};var kr=class{constructor(){this.category="MapReduce";}parse(e,o,r){e.consume("LPAREN");let n=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);n.emitOpcode(60),n.emitString("acc"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,n),e.setBuilder(r),n.emitOpcode(22);let i=n.build();if(i.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("MAP_REDUCE_TRANSFORM_MUST_BE_SYNCHRONOUS","prod's element expression must be synchronous (no weather/stocks/currency calls).");e.consume("COMMA"),te(e,r),e.consume("RPAREN"),r.emitOpcode(10),r.emitNumber(1),le(r,158,{kind:0,program:i},["acc","x"],1);}};var um={map:"MAP",reduce:"REDUCE",sum:"SUM_FN",prod:"PROD_FN"};function lp(t,e){return t?!!(t.type==="LINE_REF"||t.type==="IDENT"&&(/^line\d+$/i.test(t.value)||/^line$/i.test(t.value)&&e?.type==="NUMBER"&&/^\d+$/.test(e.value))):false}function cm(t=80){return {name:"mapreduce:call",priority:t,shape:[{types:["IDENT"],values:Object.keys(um)},{types:["LPAREN"]}],match(e,o){let r=e[o];if(!r||r.type!=="IDENT")return null;let n=r.value.toLowerCase(),i=um[n];return !i||e[o+1]?.type!=="LPAREN"||n==="sum"&&lp(e[o+2],e[o+3])?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(i,chunkYBQOQTVL_cjs.c(i),r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"mapreduce:call"}}}}var Un={name:"solve-mapreduce",normalizerRules:[cm()],prefixParselets:{MAP:new Sr,REDUCE:new Lr,SUM_FN:new vr,PROD_FN:new kr}};var wr=class{constructor(){this.category="BigInt";}parse(e,o,r){r.emitOpcode(11),r.emitString(chunkZDJTDFTR_cjs.e(o.value,e.getLocaleCode()));}};var Dn={name:"solve-bigint",prefixParselets:{BIGINT:new wr}};var re=class{constructor(e){this.opcode=e;this.category="Conditionals";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(this.opcode);}};var ke=class{constructor(e,o){this.opcode=e;this.bindingPower=o;this.category="Conditionals";}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(this.opcode);}};var ut=class{constructor(e){this.value=e;this.category="Conditionals";}parse(e,o,r){r.emitOpcode(14),r.emitByte(this.value?1:0);}};var Mr=class{constructor(){this.category="Conditionals";}parse(e,o,r){e.parseExpression(0,r),e.consume("THEN"),e.parseExpression(0,r),e.consume("ELSE"),e.parseExpression(0,r),r.emitOpcode(132);}};var bn={name:"solve-conditionals",prefixParselets:{TRUE:new ut(true),FALSE:new ut(false),IF:new Mr},infixParselets:{EQUALITY:new re(40),NEQ:new re(41),LT:new re(42),GT:new re(44),LTE:new re(43),GTE:new re(45),OR:new ke(131,chunkZDJTDFTR_cjs.a.LogicalOr),LOGICAL_AND:new ke(130,chunkZDJTDFTR_cjs.a.LogicalAnd),LOGICAL_OR:new ke(131,chunkZDJTDFTR_cjs.a.LogicalOr)}};var up={percent:74,percentage:74,decimal:70,dec:70,number:70,hex:71,fraction:140,multiplier:141,x:141,sci:142,scientific:142,binary:143,bin:143,octal:144,oct:144},pm={2:143,8:144,16:71},Br=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=e.peek();if(i?.type==="PERCENT"){e.consume(),n.emitOpcode(74);return}if(!i||i.type!=="CONVERTER_NAME"&&i.type!=="IDENT"&&i.type!=="FUNC"&&i.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("AS_CONVERTER_EXPECTED_NAME",`Expected a converter name after "as" (e.g. "as hex", "as decimal") but got ${i?`"${i.value}"`:"end of input"}`);e.consume();let a=i.value.toLowerCase();if(a==="base"){let l=e.peek(),u=l?.type==="NUMBER"?Number(l.value):NaN,c=pm[u];if(c===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("AS_CONVERTER_UNSUPPORTED_BASE",`"as base ${l?.value??"?"}": only bases ${Object.keys(pm).join(", ")} can be written out`);e.consume(),n.emitOpcode(c);return}let s=up[a];if(s!==void 0){s===141&&e.match("OF")&&(e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitOpcode(23)),n.emitOpcode(s);return}n.emitOpcode(13),n.emitString(a),n.emitOpcode(145);}};var fm={ten:10,hundred:100,thousand:1e3,million:1e6,billion:1e9};function dm(t,e,o){t.emitOpcode(10),t.emitNumber(e),t.emitOpcode(23),Em(t,o),t.emitOpcode(10),t.emitNumber(e),t.emitOpcode(22);}function Em(t,e){let o=e==="up"?pp:e==="down"?fp:cp;t.emitOpcode(51),t.emitIndex(o),t.emitIndex(1);}var cp=8,pp=6,fp=7,dp=97;function Ep(t){let o=(t.peek()?.text??"").toLowerCase();return o==="up"?(t.consume(),"up"):o==="down"?(t.consume(),"down"):"nearest"}var Ur=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=Ep(e);if(e.match("TO_NEAREST")){dm(n,Tm(e),i);return}Em(n,i);}},Dr=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){dm(n,Tm(e),"nearest");}};function Tm(t){let e=t.peek(),o=(e?.text??"").toLowerCase(),r=fm[o];if(r!==void 0)return t.consume(),r;if(e?.type==="NUMBER"){t.consume();let n=Number(e.value);if(Number.isFinite(n)&&n>0)return n}throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_ROUNDING_INCREMENT",`"to nearest ${e?.value??"?"}": expected a positive number or one of ${Object.keys(fm).join(", ")}`)}var br=class{constructor(){this.category="Converters";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=Number(r.value);if(!Number.isFinite(i)||i<0||i>100)throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_DECIMAL_PLACES",`"to ${r.value} dp": expected a place count between 0 and 100`);n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(51),n.emitIndex(dp),n.emitIndex(2);}};var Tp=new Set(["dp","dps","decimals","digits","digit"]),Np=new Set(["decimal"]);function Nm(t=66){return {name:"converters:decimal-places",priority:t,shape:[{types:["TO"]},{types:["NUMBER"]}],match(e,o){if(e[o]?.type!=="TO")return null;let r=e[o+1];if(r?.type!=="NUMBER")return null;let n=e[o+2];if(!n)return null;let i=(n.text??n.value??"").toLowerCase(),a=3;if(Np.has(i)){let l=(e[o+3]?.text??"").toLowerCase();if(l!=="place"&&l!=="places")return null;a=4;}else if(!Tp.has(i))return null;return {consumed:a,replacement:[chunkZSLVLMO5_cjs.b("DECIMAL_PLACES",r.value,e.slice(o,o+a))],ruleName:"converters:decimal-places"}}}}var yp=new Set(["hex","bin"]);function ym(t=67){return {name:"converters:preposition",priority:t,shape:[{types:["IN","TO"]},{types:["CONVERTER_NAME","FUNC"]}],match(e,o){let r=e[o];if(r?.type!=="IN"&&r?.type!=="TO")return null;let n=e[o+1];return n?.type==="CONVERTER_NAME"||n?.type==="FUNC"&&yp.has(n.value.toLowerCase())?{consumed:1,replacement:[chunkZSLVLMO5_cjs.b("AS","as",[r])],ruleName:"converters:preposition"}:null}}}var Vn={name:"solve-converters",phrases:{"to nearest":"TO_NEAREST","to the nearest":"TO_NEAREST"},infixParselets:{AS:new Br,ROUNDED:new Ur,TO_NEAREST:new Dr,DECIMAL_PLACES:new br},normalizerRules:[Nm(),ym()]};var z=class{constructor(e){this.builtinIndex=e;this.category="MathPhrases";}parse(e,o,r){let n=0;for(e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++;e.match("COMMA")||e.match("AND_CONJ");)e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++;r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(n);}};var Vr=class{constructor(e){this.builtinIndex=e;this.category="MathPhrases";}parse(e,o,r){let n=0;do{if(e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),n++,!e.match("RATE_AT")&&!e.match("AT")){let i=e.peek();throw chunkGXO7TSXQ_cjs.c.parsing("WEIGHTED_AVERAGE_MISSING_WEIGHT",'weighted average: each value needs a weight, as in "72 at 30%"',{actualType:i?.type,actualValue:i?.value})}e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),n++,this.skipWeightLabel(e);}while(e.match("COMMA")||e.match("AND_CONJ"));r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(n);}skipWeightLabel(e){for(;;){let o=e.peek();if(!o)return;if(o.type==="STAR"||o.type==="IDENT"||o.type==="UNIT"){e.consume();continue}return}}};function Fn(t){return {category:"MathPhrases",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(t),r.emitIndex(1);}}}var Pm={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),!t.match("DIVIDE_BY")&&!t.match("SLASH"))throw chunkGXO7TSXQ_cjs.c.parsing("REMAINDER_EXPECTED_DIVIDED_BY",'Expected "divided by" or "/", as in "remainder of 21 divided by 5"');t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),o.emitOpcode(24);}},_m={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Product,o),!t.match("OF"))throw chunkGXO7TSXQ_cjs.c.parsing("ROOT_EXPECTED_OF",'Expected "of", as in "root 5 of 100"');t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),o.emitOpcode(2),o.emitOpcode(10),o.emitNumber(1),o.emitOpcode(2),o.emitOpcode(23),o.emitOpcode(25);}},Am={category:"MathPhrases",parse(t,e,o){if(t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),gm(o),!t.match("LOG_BASE"))throw chunkGXO7TSXQ_cjs.c.parsing("LOG_EXPECTED_BASE",'Expected "base", as in "log 20 base 4"');t.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,o),gm(o),o.emitOpcode(23);}},gp=5;function gm(t){t.emitOpcode(51),t.emitIndex(gp),t.emitIndex(1);}function xm(t=69){return {name:"mathphrases:function-phrase",priority:t,shape:[{types:["FUNC"],values:["root","log"]}],match(e,o){let r=e[o];if(r?.type!=="FUNC")return null;let n=(r.value??"").toLowerCase();if(n!=="root"&&n!=="log"||e[o+1]?.type==="LPAREN")return null;if(n==="root")return {consumed:1,replacement:[chunkZSLVLMO5_cjs.b("NTH_ROOT","root",[r])],ruleName:"mathphrases:function-phrase"};let i=Pp(e,o+1);if(i===-1)return null;let a=e.slice(o,i+1).map((s,l)=>l===0?chunkZSLVLMO5_cjs.b("LOG_PHRASE","log",[s]):l===i-o?chunkZSLVLMO5_cjs.b("LOG_BASE","base",[s]):s);return {consumed:i-o+1,replacement:a,ruleName:"mathphrases:function-phrase"}}}}function Pp(t,e){for(let o=e;o<t.length&&o<e+8;o++){let r=t[o];if(r.type==="EOF"||r.type==="COMMA"||r.type==="RPAREN")return -1;if((r.text??r.value??"").toLowerCase()==="base")return o}return -1}function ct(t){return {category:"MathPhrases",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(t),r.emitIndex(2);}}}var Rm={category:"MathPhrases",parse(t,e,o){t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),o.emitOpcode(10),o.emitNumber(2),o.emitOpcode(23);}};var Om={category:"MathPhrases",parse(t,e,o){t.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,o),t.consume("AND_CONJ"),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),o.emitOpcode(20),o.emitOpcode(10),o.emitNumber(2),o.emitOpcode(23);}};var Cm=mr({category:"MathPhrases",alternatives:[{slots:[{kind:"keyword",tokenTypes:["BETWEEN"]},{kind:"expr",bindingPower:chunkZDJTDFTR_cjs.a.Product},{kind:"keyword",tokenTypes:["AND_CONJ"]},{kind:"expr"}],emit:t=>{t.emitOpcode(51),t.emitIndex(37),t.emitIndex(2);}}]});var _p=47,Fr=class{constructor(){this.category="MathPhrases";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let n=e.peek();if(n?.type==="BETWEEN")e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);else if(n?.type==="FROM")e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("TO"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);else throw chunkGXO7TSXQ_cjs.c.parsing("CLAMP_EXPECTED_BETWEEN_OR_FROM",`Expected "between" or "from" after "clamp <value>" but got ${n?`"${n.value}"`:"end of input"}`);r.emitOpcode(51),r.emitIndex(_p),r.emitIndex(3);}};var Ap=46,Hr=class{constructor(){this.category="MathPhrases";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),e.consume("AS"),e.parseExpression(this.bindingPower,n),e.consume("IS_TO");let i=e.consume();if(!i||i.value.toLowerCase()!=="what")throw chunkGXO7TSXQ_cjs.c.parsing("PROPORTION_EXPECTED_WHAT",`Expected "what" but got ${i?`"${i.value}"`:"end of input"}`);n.emitOpcode(51),n.emitIndex(Ap),n.emitIndex(3);}};var xp=42,Rp=43,Op=44,Cp=45,Ip=9,hp=10,Sp=101,Lp=102,vp=103,kp=104,wp=105,Mp=106,Bp=107,Up=38,Dp=39,bp=0,Vp=21,Hn={name:"solve-mathphrases",phrases:{"average of":"AVERAGE_OF","median of":"MEDIAN_OF","total of":"TOTAL_OF","count of":"COUNT_OF","larger of":"LARGER_OF","greater of":"LARGER_OF","smaller of":"SMALLER_OF","lesser of":"SMALLER_OF","half of":"HALF_OF","midpoint between":"MIDPOINT_BETWEEN","random number":"RANDOM_NUMBER","is to":"IS_TO","remainder of":"REMAINDER_OF","gcd of":"GCD_OF","lcm of":"LCM_OF","square root of":"SQUARE_ROOT_OF","cube root of":"CUBE_ROOT_OF","standard deviation of":"STANDARD_DEVIATION_OF","stdev of":"STANDARD_DEVIATION_OF","sample standard deviation of":"SAMPLE_STANDARD_DEVIATION_OF","sample stdev of":"SAMPLE_STANDARD_DEVIATION_OF","variance of":"VARIANCE_OF","sample variance of":"SAMPLE_VARIANCE_OF","spread of":"SPREAD_OF","mode of":"MODE_OF","weighted average of":"WEIGHTED_AVERAGE_OF","weighted mean of":"WEIGHTED_AVERAGE_OF"},prefixParselets:{AVERAGE_OF:new z(xp),MEDIAN_OF:new z(Rp),TOTAL_OF:new z(Op),COUNT_OF:new z(Cp),LARGER_OF:ct(hp),SMALLER_OF:ct(Ip),HALF_OF:Rm,MIDPOINT_BETWEEN:Om,RANDOM_NUMBER:Cm,REMAINDER_OF:Pm,NTH_ROOT:_m,LOG_PHRASE:Am,GCD_OF:ct(Up),LCM_OF:ct(Dp),SQUARE_ROOT_OF:Fn(bp),CUBE_ROOT_OF:Fn(Vp),CLAMP:new Fr,STANDARD_DEVIATION_OF:new z(Sp),SAMPLE_STANDARD_DEVIATION_OF:new z(Lp),VARIANCE_OF:new z(vp),SAMPLE_VARIANCE_OF:new z(kp),SPREAD_OF:new z(wp),MODE_OF:new z(Mp),WEIGHTED_AVERAGE_OF:new Vr(Bp)},infixParselets:{IS_TO:new Hr},normalizerRules:[xm()]};var Im={annually:1,yearly:1,"semi-annually":2,quarterly:4,monthly:12,fortnightly:26,weekly:52,daily:365};function Gn(t){if(!t.match("COMPOUNDING"))return 1;let e=t.peek(),o=(e?.text??e?.value??"").toLowerCase(),r=Im[o];if(r===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("UNKNOWN_COMPOUNDING_INTERVAL",`compounding ${o||"?"}: expected one of ${Object.keys(Im).join(", ")}`);return t.consume(),r}var pt=class{constructor(e,o){this.annualIndex=e;this.intervalIndex=o;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n);let i=Gn(e);if(n.emitOpcode(2),i===1){n.emitOpcode(51),n.emitIndex(this.annualIndex),n.emitIndex(3);return}n.emitOpcode(10),n.emitNumber(i),n.emitOpcode(51),n.emitIndex(this.intervalIndex),n.emitIndex(4);}},Gr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),!e.match("AFTER")&&!e.match("OVER")&&!e.match("IN")&&e.consume("AFTER"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),r.emitOpcode(2),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}},zr=class{constructor(e){this.builtinIndex=e;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.consume("RETURNED"),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}},Kr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("INVESTED"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("RETURNED"),!e.match("AFTER")&&!e.match("OVER")&&!e.match("IN")&&e.consume("AFTER"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}};function $r(t,e,o){return Sm(t,o)?(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),hm(t),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),{swap:true}):(hm(t),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),Fp(t,o),t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,e),{swap:false})}function Sm(t,e){for(let o of e)if(t.match(o))return true;return false}function Fp(t,e){Sm(t,e)||t.consume(e[0]);}function hm(t){t.match("RATE_AT")||t.consume("AT");}var ft=class{constructor(e,o){this.builtinIndex=e;this.intervalIndex=o;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r);let{swap:n}=$r(e,r,["AFTER","FOR_DURATION","OVER"]),i=Gn(e);if(n&&r.emitOpcode(2),i===1){r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);return}r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(51),r.emitIndex(this.intervalIndex),r.emitIndex(4);}};var X=class{constructor(e,o){this.builtinIndex=e;this.periodsPerYear=o;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let{swap:n}=$r(e,r,["OVER"]);n&&r.emitOpcode(2),r.emitOpcode(10),r.emitNumber(this.periodsPerYear),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(4);}};var Wr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("BETWEEN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.match("PEOPLE"),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(2);}},Yr=class{constructor(e){this.builtinIndex=e;this.category="Finance";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),e.consume("WAYS"),n.emitOpcode(51),n.emitIndex(this.builtinIndex),n.emitIndex(2);}};var Lm={daily:{perYear:365,unit:"days"},weekly:{perYear:52,unit:"weeks"},monthly:{perYear:12,unit:"months"},yearly:{perYear:1,unit:"years"},annually:{perYear:1,unit:"years"}};function Hp(t){let e=t.peek(),o=(e?.text??e?.value??"").toLowerCase(),r=Lm[o];if(r===void 0)throw chunkGXO7TSXQ_cjs.c.parsing("UNKNOWN_SAVINGS_PERIOD",`savings goal: expected a contribution period, one of ${Object.keys(Lm).join(", ")}, not "${o||"?"}".`);return t.consume(),r}var jr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.consume("AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.match("STAR");let n=Hp(e);r.emitOpcode(10),r.emitNumber(n.perYear),e.match("RATE_AT")||e.match("AT")?e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r):(r.emitOpcode(10),r.emitNumber(0)),r.emitOpcode(13),r.emitString(n.unit),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(5);}},Xr=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.match("RATE_AT")||e.match("AT")?e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r):(r.emitOpcode(10),r.emitNumber(0)),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(3);}};var we=class{constructor(e){this.builtinIndex=e;this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("RATE_AT"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(this.builtinIndex),r.emitIndex(2);}};var Gp=60;function zp(t){for(let e=0;;e++){let o=t.peekAt(e);if(!o)return false;if(o.type==="FROM"||o.type==="WORTH_IN")return true}}var dt=class{constructor(e){this.variant=e;this.category="Finance";}parse(e,o,r){if(!zp(e)){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);return}if(e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),this.variant==="what-was"){e.consume("WORTH_IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("inflationToYearFromPresent",2);return}let n=e.peek();if(n?.type==="FROM"){e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall("inflationFromYearToPresent",2);return}if(n?.type==="IN"){e.consume(),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("WORTH_IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitOpcode(51),r.emitIndex(Gp),r.emitIndex(3);return}let i=n?n.type:"end of input";throw chunkGXO7TSXQ_cjs.c.parsing("INFLATION_EXPECTED_FROM_OR_IN",`Expected "from <year>" or "in <year> worth in <year>" after "what is <amount>", got ${i}`)}};var Qr=class{constructor(){this.category="Finance";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Product,r),e.consume("IN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("ASSUMING"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r);let n=e.peek();if((n&&n.type==="IDENT"?n.value.toLowerCase():void 0)!=="inflation"){let a=n?n.value:"end of input";throw chunkGXO7TSXQ_cjs.c.parsing("INFLATION_EXPECTED_INFLATION_WORD",`Expected the word "inflation" after "assuming <rate>%", got "${a}"`)}e.consume(),r.emitPluginCall("inflationFutureValue",3);}};var qr=class{constructor(){this.category="Finance";this.bindingPower=35;}parse(e,o,r,n){let i=Number(r.value);n.emitOpcode(10),n.emitNumber(i),n.emitPluginCall("inflationToYearFromPresent",2);}};function zn(t){let e=chunkTPPM4QSS_cjs.c(t);return e.fields(e.now()).year}function vm(t,e){return chunkGJZIJK2Q_cjs.P(t,`Year ${e} is outside the bundled CPI table's range (${chunkQQHHZPEW_cjs.z}-${chunkQQHHZPEW_cjs.A})`)}function km(t,e){let o=t[0],r=t[1].toNumber(),n=zn(e),i=chunkQQHHZPEW_cjs.B(o.toNumber(),r,n);return i===void 0?vm("INFLATION_YEAR_OUT_OF_RANGE",r):o.type===6?chunkGJZIJK2Q_cjs.u(i,o.unit):chunkGJZIJK2Q_cjs.n(i)}function wm(t,e){let o=t[0],r=zn(e),n=t[1].toNumber(),i=chunkQQHHZPEW_cjs.B(o.toNumber(),r,n);return i===void 0?vm("INFLATION_YEAR_OUT_OF_RANGE",n):o.type===6?chunkGJZIJK2Q_cjs.u(i,o.unit):chunkGJZIJK2Q_cjs.n(i)}function Mm(t,e){let o=t[0],r=t[1].toNumber(),n=t[2].toNumber(),i=r-zn(e);if(1+n<=0)return chunkGJZIJK2Q_cjs.P("INVALID_RATE",`inflationFutureValue: rate ${n} makes (1 + rate) non-positive`);let s=o.toNumber()/Math.pow(1+n,i);return o.type===6?chunkGJZIJK2Q_cjs.u(s,o.unit):chunkGJZIJK2Q_cjs.n(s)}function Bm(t=70){return {name:"finance:in-year-dollars",priority:t,shape:[{types:["IN"]},{types:["NUMBER"]}],match(e,o){let r=e[o],n=e[o+1],i=e[o+2];if(r.type!=="IN"||n?.type!=="NUMBER"||i?.type!=="IDENT"&&i?.type!=="UNIT")return null;let a=i.value.toLowerCase();return a!=="dollars"&&a!=="dollar"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("IN_YEAR_DOLLARS",n.value,e.slice(o,o+3))],ruleName:"finance:in-year-dollars"}}}}var Kp={RECURRING_INTERVAL_NOT_POSITIVE:"RECURRING_INTERVAL_NOT_POSITIVE"},$p={daily:365,weekly:52,monthly:12,yearly:1,annually:1},Wp={day:365,days:365,week:52,weeks:52,month:12,months:12,year:1,years:1},Yp=new Set(["a","an"]),jp=new Set(["NUMBER","FLOAT","HEX","BIGINT","RPAREN","RBRACKET","IDENT","PERCENT","STRING"]);function Et(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}function Um(t){if(!(t===void 0||t.type!=="UNIT"))return Wp[Et(t)]}function Xp(t,e){let o=t[e];if(o===void 0)return null;if(o.type==="IDENT"){let r=$p[Et(o)];if(r!==void 0)return {perYear:r,consumed:1};if(Et(o)==="every"){let n=t[e+1];if(n?.type!=="NUMBER")return null;let i=Um(t[e+2]);if(i===void 0)return null;let a=Number((n.value??"").replace(/,/g,""));if(!(a>0))throw chunkGXO7TSXQ_cjs.c.parsing({code:Kp.RECURRING_INTERVAL_NOT_POSITIVE,message:`A recurring interval must be a positive number, not "${n.value}".`,expected:"a positive interval, e.g. every 2 weeks",found:`every ${n.value} ${Et(t[e+2])}`});return {perYear:i/a,consumed:3}}}return null}function Qp(t,e){let o=t[e];if(o===void 0)return null;let r,n;if(o.type==="NUMBER")r=Number((o.value??"").replace(/,/g,"")),n=e+1;else if(o.type==="IDENT"&&Yp.has(Et(o)))r=1,n=e+1;else return null;let i=Um(t[n]);return i===void 0||!Number.isFinite(r)||r<0?null:{years:r/i,consumed:n-e+1}}function qp(t,e){let o=t*e,r=Math.round(o);return Math.abs(o-r)<1e-9?r:Math.floor(o)}function Dm(t=78){return {name:"finance:recurring-schedule",priority:t,unshapedReason:"Scans forward through a period and a duration sub-grammar of unbounded length, so no fixed leading shape describes it.",match(e,o){let r=e[o];if(r===void 0||!jp.has(r.type))return null;let n=Xp(e,o+1);if(n===null)return null;let i=o+1+n.consumed;if(e[i]?.type!=="FOR_DURATION")return null;let a=Qp(e,i+1);if(a===null)return null;let s=qp(n.perYear,a.years),l=i+1+a.consumed-o,u=e.slice(o,o+l);return {replacement:[r,chunkZSLVLMO5_cjs.b("STAR","*",u),chunkZSLVLMO5_cjs.b("NUMBER",String(s),u)],consumed:l,ruleName:"finance:recurring-schedule"}}}}function Zr(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}var bm=new Set(["NUMBER","FLOAT","HEX","BIGINT","RPAREN","RBRACKET","IDENT","PERCENT","STRING"]),Vm=new Set(["NUMBER","FLOAT"]);function Fm(t=77){return {name:"finance:bill-split",priority:t,unshapedReason:"Scans forward an unbounded distance for the BETWEEN keyword, and starts at any value-ending token.",match(e,o){let r=e[o];if(r===void 0)return null;if(bm.has(r.type)){let f=e[o+1],T=e[o+2],N=e[o+3];if(f?.type==="IDENT"&&Zr(f)==="split"&&T!==void 0&&Vm.has(T.type)&&N?.type==="IDENT"&&Zr(N)==="ways")return {consumed:4,replacement:[r,chunkZSLVLMO5_cjs.b("SPLIT_WAYS","split",[f]),T,chunkZSLVLMO5_cjs.b("WAYS","ways",[N])],ruleName:"finance:bill-split"}}if(r.type!=="IDENT"||Zr(r)!=="split")return null;let n=e[o-1];if(n!==void 0&&bm.has(n.type))return null;let i=-1;for(let f=o+1;f<e.length;f++)if(e[f].type==="BETWEEN"){i=f;break}if(i===-1)return null;let a=e[i+1];if(a===void 0||!Vm.has(a.type))return null;let s=i+2,l=e[s]?.type==="IDENT"&&Zr(e[s])==="people",u=l?s:i+1,c=[chunkZSLVLMO5_cjs.b("SPLIT","split",[r]),...e.slice(o+1,i+2)];return l&&c.push(chunkZSLVLMO5_cjs.b("PEOPLE","people",[e[s]])),{consumed:u-o+1,replacement:c,ruleName:"finance:bill-split"}}}}var Kn=51,Zp=52,Jr=55,eo=56,$n=80,Jp=81,ef=82,tf=83,rf=84,of=59,nf=85,af=86,Hm=98,sf=99,mf=100,Wn={name:"solve-finance",phrases:{"compound interest on":"COMPOUND_INTEREST_ON","interest on":"INTEREST_ON","daily repayment on":"DAILY_REPAYMENT_ON","monthly repayment on":"MONTHLY_REPAYMENT_ON","annual repayment on":"ANNUAL_REPAYMENT_ON","total repayment on":"TOTAL_REPAYMENT_ON","daily interest on":"DAILY_LOAN_INTEREST_ON","monthly interest on":"MONTHLY_LOAN_INTEREST_ON","annual interest on":"ANNUAL_LOAN_INTEREST_ON","total interest on":"TOTAL_LOAN_INTEREST_ON","tax on":"TAX_ON","tax off":"TAX_OFF","tax in":"TAX_IN_PHRASE","tax of":"TAX_IN_PHRASE","tax from":"TAX_IN_PHRASE","vat in":"TAX_IN_PHRASE","vat of":"TAX_IN_PHRASE","vat from":"TAX_IN_PHRASE","vat on":"TAX_ON","vat off":"TAX_OFF","what is":"WHAT_IS","what was":"WHAT_WAS","present value of":"PRESENT_VALUE_OF","annual return on":"ANNUAL_RETURN_ON","value of":"VALUE_OF","worth in":"WORTH_IN","how long to save":"SAVINGS_HOW_LONG","how much per month to save":"SAVINGS_HOW_MUCH","how much per month to reach":"SAVINGS_HOW_MUCH",assuming:"ASSUMING"},prefixParselets:{PRESENT_VALUE_OF:new Gr(ef),ANNUAL_RETURN_ON:new Kr(rf),COMPOUND_INTEREST_ON:new ft(Kn,$n),INTEREST_ON:new ft(Zp,Jp),DAILY_REPAYMENT_ON:new X(Jr,365),MONTHLY_REPAYMENT_ON:new X(Jr,12),ANNUAL_REPAYMENT_ON:new X(Jr,1),TOTAL_REPAYMENT_ON:new X(Jr,0),DAILY_LOAN_INTEREST_ON:new X(eo,365),MONTHLY_LOAN_INTEREST_ON:new X(eo,12),ANNUAL_LOAN_INTEREST_ON:new X(eo,1),TOTAL_LOAN_INTEREST_ON:new X(eo,0),TAX_ON:new we(af),TAX_OFF:new we(of),TAX_IN_PHRASE:new we(nf),SPLIT:new Wr(Hm),WHAT_IS:new dt("what-is"),WHAT_WAS:new dt("what-was"),VALUE_OF:new Qr,SAVINGS_HOW_LONG:new jr(mf),SAVINGS_HOW_MUCH:new Xr(sf)},infixParselets:{AFTER:new pt(Kn,$n),FOR_DURATION:new pt(Kn,$n),INVESTED:new zr(tf),IN_YEAR_DOLLARS:new qr,SPLIT_WAYS:new Yr(Hm)},normalizerRules:[Bm(),Dm(),Fm()],pluginFunctions:{inflationFromYearToPresent:km,inflationToYearFromPresent:wm,inflationFutureValue:Mm}};function lf(t){return (e,o)=>chunkGJZIJK2Q_cjs.P(`${t.toUpperCase()}_QUERY_FAILED`,`Failed to resolve "${e}": ${o instanceof Error?o.message:String(o)}`)}function oe(t){let e=t.staleTimeMs??3e5,o=t.timeoutMs??1e4,r=t.failureCooldownMs??3e4,n=t.onError??lf(t.namespace),i=u=>[t.namespace,u];async function a(u,c,f){let{signal:T,cleanup:N}=chunkTLG7VZRX_cjs.a(c,o,`${t.namespace} query`);try{return await t.fetchQuery(u,T)}catch(E){let P=n(u,E);return setTimeout(()=>{f.getQueryData(i(u))===P&&f.removeQueries({queryKey:i(u),exact:true});},r).unref?.(),P}finally{N();}}return {resolver:{namespace:t.namespace,preflight(u,c,f,T,N){let{opcodes:E,strings:P}=c,R=E.length,O=0;for(;O<R;){if(E[O]===50&&O+2<R){let A=E[O+1],S=E[O+2];if(A===t.pluginFunctionIndex&&S>=1&&O>=2&&E[O-2]===13){let v=P[E[O-1]],q=i(v);if(N.getQueryData(q)===void 0){let Ye=N.fetchQuery({queryKey:q,queryFn:({signal:jo})=>a(v,jo,N),staleTime:e}),pe={queryKey:q.join(":"),resolver:Ye,packageId:f,signal:T,metadata:{query:v}};return t.refetchIntervalMs!==void 0&&(pe.refetchIntervalMs=t.refetchIntervalMs,pe.refetch=()=>N.fetchQuery({queryKey:q,queryFn:({signal:jo})=>a(v,jo,N),staleTime:0})),pe}}O+=3;continue}O=chunkG2V33LFM_cjs.a(E,O);}return null},destroy(){}},pluginFunction:(u,c)=>{let f=u[0]?.value,T=chunkZLRJ7TDP_cjs.b()?.getQueryData(i(f));return T!==void 0?T:c?.networkEnabled===false?chunkGJZIJK2Q_cjs.P("NETWORK_DISABLED",`Live data is switched off for this engine (network.enabled is false), so "${f}" was not fetched`):chunkGJZIJK2Q_cjs.P(`${t.namespace.toUpperCase()}_NOT_PREFLIGHTED`,`No cached result for "${f}"`)}}}function uf(t,e){let o=[];for(;t.peek()?.type==="IDENT";)o.push(t.consume().value);if(o.length===0)throw chunkGXO7TSXQ_cjs.c.parsing("WEATHER_EXPECTED_CITY",`Expected a city name after "${e}" (e.g. "${e} London")`);return o.join(" ")}function Me(t,e){return {category:"Weather",parse(o,r,n){let i=uf(o,r.value);n.emitOpcode(13),n.emitString(`${t}:${i}`),n.emitPluginCall(e,1);}}}var cf={0:"clear sky",1:"mainly clear",2:"partly cloudy",3:"overcast",45:"fog",48:"depositing rime fog",51:"light drizzle",53:"moderate drizzle",55:"dense drizzle",56:"light freezing drizzle",57:"dense freezing drizzle",61:"slight rain",63:"moderate rain",65:"heavy rain",66:"light freezing rain",67:"heavy freezing rain",71:"slight snow fall",73:"moderate snow fall",75:"heavy snow fall",77:"snow grains",80:"slight rain showers",81:"moderate rain showers",82:"violent rain showers",85:"slight snow showers",86:"heavy snow showers",95:"thunderstorm",96:"thunderstorm with slight hail",99:"thunderstorm with heavy hail"};function Gm(t){return cf[t]??`weather code ${t}`}var Be={GEOCODING_API_ERROR:"WEATHER_GEOCODING_API_ERROR",CITY_NOT_FOUND:"WEATHER_CITY_NOT_FOUND",FORECAST_API_ERROR:"WEATHER_FORECAST_API_ERROR",FORECAST_RESPONSE_MALFORMED:"WEATHER_FORECAST_RESPONSE_MALFORMED",UNKNOWN_QUERY_KIND:"WEATHER_UNKNOWN_QUERY_KIND"},pf="https://geocoding-api.open-meteo.com/v1/search",ff="https://api.open-meteo.com/v1/forecast",df=1e4;async function Ef(t,e){let o=`${pf}?name=${encodeURIComponent(t)}&count=1&language=en&format=json`,r=await fetch(o,{signal:e});if(!r.ok)throw chunkGXO7TSXQ_cjs.c.external(Be.GEOCODING_API_ERROR,`Open-Meteo geocoding API returned ${r.status} for "${t}"`,{city:t,status:r.status});let i=(await r.json())?.results?.[0];if(!i)throw chunkGXO7TSXQ_cjs.c.validation(Be.CITY_NOT_FOUND,`No location found for "${t}"`,{city:t});return {latitude:i.latitude,longitude:i.longitude,name:i.name}}async function Tf(t,e,o){let r=new URLSearchParams({latitude:String(t),longitude:String(e),current:"temperature_2m,apparent_temperature,weather_code",daily:"temperature_2m_max,temperature_2m_min",timezone:"auto",forecast_days:"1"}),n=await fetch(`${ff}?${r.toString()}`,{signal:o});if(!n.ok)throw chunkGXO7TSXQ_cjs.c.external(Be.FORECAST_API_ERROR,`Open-Meteo forecast API returned ${n.status}`,{status:n.status});let i=await n.json(),a=i?.current,s=i?.daily;if(!a||!s)throw chunkGXO7TSXQ_cjs.c.external(Be.FORECAST_RESPONSE_MALFORMED,"Open-Meteo forecast response missing current/daily blocks");return {weatherCode:a.weather_code,temperature:a.temperature_2m,apparentTemperature:a.apparent_temperature,high:s.temperature_2m_max?.[0],low:s.temperature_2m_min?.[0]}}var to=new Map,Nf=6e4;function zm(t,e){let o=t.trim().toLowerCase(),r=Date.now(),n=to.get(o);if(n&&n.expiresAt>r)return n.promise;let{signal:i,cleanup:a}=chunkTLG7VZRX_cjs.a(e,df,"Open-Meteo weather query"),s=(async()=>{try{let l=await Ef(t,i),u=await Tf(l.latitude,l.longitude,i);return {resolvedName:l.name,weatherCode:u.weatherCode,description:Gm(u.weatherCode),temperature:u.temperature,apparentTemperature:u.apparentTemperature,high:u.high,low:u.low}}finally{a();}})();return to.set(o,{promise:s,expiresAt:r+Nf}),s.catch(()=>{to.get(o)?.promise===s&&to.delete(o);}),s}var Km="solve-weather",Te="weather",yf=chunkQQHHZPEW_cjs.F(`${Km}:${Te}`),{resolver:gf,pluginFunction:Pf}=oe({namespace:"weather",pluginFunctionIndex:yf,staleTimeMs:600*1e3,fetchQuery:async(t,e)=>{let o=t.indexOf(":"),r=o===-1?t:t.slice(0,o),n=o===-1?"":t.slice(o+1),i=await zm(n,e);switch(r){case "current":return chunkGJZIJK2Q_cjs.t(`${Math.round(i.temperature)}\xB0C, ${i.description}`);case "temperature":return chunkGJZIJK2Q_cjs.u(i.temperature,"C");case "feelslike":return chunkGJZIJK2Q_cjs.u(i.apparentTemperature,"C");case "high":return chunkGJZIJK2Q_cjs.u(i.high,"C");case "low":return chunkGJZIJK2Q_cjs.u(i.low,"C");default:throw chunkGXO7TSXQ_cjs.c.internal(Be.UNKNOWN_QUERY_KIND,`Unknown weather query kind "${r}"`,{kind:r})}}}),Yn={name:Km,phrases:{"weather in":"WEATHER_IN","temperature in":"TEMPERATURE_IN","feels like in":"FEELS_LIKE_IN","high in":"HIGH_IN","low in":"LOW_IN"},prefixParselets:{WEATHER_IN:Me("current",Te),TEMPERATURE_IN:Me("temperature",Te),FEELS_LIKE_IN:Me("feelslike",Te),HIGH_IN:Me("high",Te),LOW_IN:Me("low",Te)},pluginFunctions:{[Te]:Pf},asyncResolvers:[gf]};var ro={jan:0,january:0,feb:1,february:1,mar:2,march:2,apr:3,april:3,may:4,jun:5,june:5,jul:6,july:6,aug:7,august:7,sep:8,sept:8,september:8,oct:9,october:9,nov:10,november:10,dec:11,december:11};function no(t){return t<10?`0${t}`:String(t)}function Tt(t,e,o,r,n){let i=n.fields(n.localMidnight(t,e,o));if(i.year!==t||i.month0!==e||i.day!==o)throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`"${r}" is not a valid calendar date`);return {isoDate:`${t}-${no(e+1)}-${no(o)}`,raw:r}}function oo(t,e){if(!/^\d{4}$/.test(t))throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`Expected a 4-digit year in "${e}", got "${t}"`);return parseInt(t,10)}function $m(t){let e=t.peek();if(!e)return null;let o=t.getCalendar();if(e.type==="DATETIME_LITERAL"){t.consume();let r=o.fields(Number(e.value));return Number.isNaN(r.year)?null:{isoDate:`${r.year}-${no(r.month0+1)}-${no(r.day)}`,raw:e.text??e.value}}if(e.type==="NUMBER"){let r=t.consume(),n=t.peek();if(n&&(n.type==="SLASH"||n.type==="MINUS")){let a=n.type;t.consume();let s=t.consume("NUMBER");t.consume(a);let l=t.consume("NUMBER"),u=`${r.value}${a==="SLASH"?"/":"-"}${s.value}${a==="SLASH"?"/":"-"}${l.value}`;if(a==="SLASH"){let c=parseInt(r.value,10),f=parseInt(s.value,10),T=oo(l.value,u);return Tt(T,c-1,f,u,o)}else {if(/^\d{4}$/.test(r.value)){let N=parseInt(r.value,10),E=parseInt(s.value,10),P=parseInt(l.value,10);return Tt(N,E-1,P,u,o)}let c=parseInt(r.value,10),f=parseInt(s.value,10),T=oo(l.value,u);return Tt(T,c-1,f,u,o)}}let i=t.peek();if(i&&i.type==="IDENT"&&ro[i.value.toLowerCase()]!==void 0){let a=ro[i.value.toLowerCase()];t.consume(),t.peek()?.type==="COMMA"&&t.consume();let s=t.consume("NUMBER"),l=`${r.value} ${i.value} ${s.value}`,u=oo(s.value,l);return Tt(u,a,parseInt(r.value,10),l,o)}throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_DATE",`Expected a date after "on" (e.g. "April 12, 2005" or "4/12/2005"), got "${r.value}"`)}if(e.type==="IDENT"&&ro[e.value.toLowerCase()]!==void 0){let r=ro[e.value.toLowerCase()];t.consume();let n=t.consume("NUMBER");t.peek()?.type==="COMMA"&&t.consume();let i=t.consume("NUMBER"),a=`${e.value} ${n.value}, ${i.value}`,s=oo(i.value,a);return Tt(s,r,parseInt(n.value,10),a,o)}return null}var jn=new Set(["AAPL","MSFT","GOOGL","GOOG","AMZN","META","NVDA","TSLA","NFLX","ADBE","CRM","ORCL","IBM","INTC","AMD","CSCO","PYPL","UBER","ABNB","SPOT","SHOP","SQ","COIN","PLTR","SNOW","ZM","JPM","V","MA","BAC","WFC","GS","MS","AXP","WMT","COST","HD","NKE","SBUX","MCD","KO","PEP","DIS","TGT","BA","GE","F","GM","XOM","CVX","PFE","JNJ","UNH","MRNA","TSM","ASML","BABA"]);var Ue="STOCK_TICKER",_f=chunkYBQOQTVL_cjs.c(Ue);function Wm(){return {name:"stocks:bare-ticker",priority:20,shape:[{types:["IDENT"],values:[...jn]}],match(t,e){let o=t[e];return !o||o.type!=="IDENT"||!jn.has(o.value)||e>0&&t[e-1].type==="COLON"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(Ue,_f,o.value,o.value,o.offset,0,o.line,o.col)],ruleName:"stocks:bare-ticker"}}}}function Af(t){let e=t.peek();if(!e||e.type!=="IDENT")return null;let o=e.value.toLowerCase(),r="close";if(o==="close"||o==="volume"){r=o,t.consume();let i=t.peek();if(!i||i.type!=="IDENT"||i.value.toLowerCase()!=="on")throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_EXPECTED_ON",`Expected "on <date>" after "${o}" (e.g. "AAPL ${o} on April 12, 2005")`);t.consume();}else if(o==="on")t.consume();else return null;let n=$m(t);if(!n)throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_EXPECTED_DATE",'Expected a date after "on" (e.g. "April 12, 2005" or "4/12/2005")');return {field:r,date:n}}function Ym(t,e,o,r,n){t.emitOpcode(13),o?(t.emitString(`${o.field}:${e}:${o.date.isoDate}`),t.emitPluginCall(n,1)):(t.emitString(e),t.emitPluginCall(r,1));}function jm(t,e,o,r,n){let i=false;t.peek()?.type==="STAR"&&(t.consume(),i=true);let a=Af(t);if(i&&!a){Ym(e,o,null,r,n),t.parseExpression(chunkZDJTDFTR_cjs.a.Product,e),e.emitOpcode(22);return}Ym(e,o,a,r,n);}function Xm(t,e){return {category:"Stocks",parse(o,r,n){o.consume("LPAREN");let i=o.consume(),a;if(i.type==="STRING")a=chunkUURM7P3P_cjs.a(i.value).toUpperCase();else if(i.type==="IDENT"||i.type===Ue)a=i.value.toUpperCase();else throw chunkGXO7TSXQ_cjs.c.parsing("STOCKS_INVALID_TICKER",`Expected a ticker symbol inside stock(...), got "${i.value}" (${i.type})`);o.consume("RPAREN"),jm(o,n,a,t,e);}}}function Qm(t,e){return {category:"Stocks",parse(o,r,n){let i=r.value.toUpperCase();jm(o,n,i,t,e);}}}var Xn="solve-stocks",io="stock",ao="stockhistorical";function qm(t={}){function e(s){return chunkGJZIJK2Q_cjs.P("STOCKS_NOT_CONFIGURED",`Stock data provider not configured. Supply ${s} via createStocksPackage({ ... }); see the StocksPackage doc comment.`)}let{resolver:o,pluginFunction:r}=oe({namespace:"stocks-current",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${Xn}:${io}`),staleTimeMs:t.staleTimeMs??6e4,refetchIntervalMs:t.refetchIntervalMs,fetchQuery:async(s,l)=>{if(!t.fetchQuote)return e("fetchQuote");let u=await t.fetchQuote(s,l);return chunkGJZIJK2Q_cjs.u(u.price,u.currency??"USD")}}),{resolver:n,pluginFunction:i}=oe({namespace:"stocks-historical",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${Xn}:${ao}`),staleTimeMs:t.historicalStaleTimeMs??720*60*60*1e3,fetchQuery:async(s,l)=>{let[u,c,f]=s.split(":");if(!t.fetchHistoricalQuote)return e("fetchHistoricalQuote");let T=await t.fetchHistoricalQuote(c,f,l);return u==="volume"?chunkGJZIJK2Q_cjs.n(T.volume??0):chunkGJZIJK2Q_cjs.u(T.close,T.currency??"USD")}});return {name:Xn,lexerVocabulary:{keywords:{stock:"STOCK_FN"}},prefixParselets:{STOCK_FN:Xm(io,ao),...t.enableBareTickerRecognition?{[Ue]:Qm(io,ao)}:{}},normalizerRules:t.enableBareTickerRecognition?[Wm()]:[],pluginFunctions:{[io]:r,[ao]:i},asyncResolvers:[o,n]}}var so=class{constructor(e){this.fn=e;this.category="Crypto";}parse(e,o,r){e.consume("LPAREN");let n=e.consume(),i=String(n.value??"").trim().toUpperCase();e.consume("RPAREN"),r.emitOpcode(13),r.emitString(i),r.emitPluginCall(this.fn,1);}};var Zm="solve-crypto",Qn="crypto";function Jm(t={}){function e(){return chunkGJZIJK2Q_cjs.P("CRYPTO_NOT_CONFIGURED","Crypto price provider not configured. Supply fetchPrice via createCryptoPackage({ fetchPrice }); see the CryptoPackage doc comment.")}let{resolver:o,pluginFunction:r}=oe({namespace:"crypto",pluginFunctionIndex:chunkQQHHZPEW_cjs.F(`${Zm}:${Qn}`),staleTimeMs:t.staleTimeMs??6e4,refetchIntervalMs:t.refetchIntervalMs,fetchQuery:async(n,i)=>{if(!t.fetchPrice)return e();let a=await t.fetchPrice(n,i);return chunkGJZIJK2Q_cjs.u(a.price,a.currency??"USD")}});return {name:Zm,lexerVocabulary:{keywords:{crypto:"CRYPTO_FN"}},prefixParselets:{CRYPTO_FN:new so(Qn)},pluginFunctions:{[Qn]:r},asyncResolvers:[o],tokenCategories:{CRYPTO_FN:"function"}}}function el(t){return {category:"Knowledge",parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall(t,1);}}}function tl(t={}){let e="solve-knowledge",o="knowledge",r=chunkQQHHZPEW_cjs.F(`${e}:${o}`),{resolver:n,pluginFunction:i}=oe({namespace:"knowledge",pluginFunctionIndex:r,staleTimeMs:t.staleTimeMs??300*1e3,fetchQuery:async(a,s)=>{if(!t.answerQuery)return chunkGJZIJK2Q_cjs.P("KNOWLEDGE_NOT_CONFIGURED","Knowledge answer provider not configured. Supply answerQuery via createKnowledgePackage({ ... }); see the KnowledgePackage doc comment.");let l=await t.answerQuery(a,s);return chunkGJZIJK2Q_cjs.t(l)}});return {name:e,lexerVocabulary:{rawLinePatterns:[{pattern:/^(?:search|ask|google)\s*:\s*(.+)$/i,tokenType:"KNOWLEDGE_QUERY"},{pattern:/^(.+?)=\s*\?\s*$/,tokenType:"KNOWLEDGE_QUERY"}]},prefixParselets:{KNOWLEDGE_QUERY:el(o)},pluginFunctions:{[o]:i},asyncResolvers:[n]}}var mo=class{constructor(){this.category="Lines";}parse(e,o,r){r.emitPluginCall("prev",0);}};var lo=class{constructor(){this.category="Lines";}parse(e,o,r){let n=parseInt(o.value,10);r.emitOpcode(10),r.emitNumber(n),r.emitPluginCall("lineRef",1);}};var Nt=class{constructor(e){this.isAverage=e;this.category="Lines";}parse(e,o,r){e.consume("LPAREN");let n=e.consume("LINE_REF");e.consume("COLON");let i=e.consume("LINE_REF");e.consume("RPAREN");let a=parseInt(n.value,10),s=parseInt(i.value,10);r.emitOpcode(10),r.emitNumber(a),r.emitOpcode(10),r.emitNumber(s),r.emitPluginCall(this.isAverage?"averageRange":"sumRange",2);}};var De=class{constructor(e){this.isAverage=e;this.category="Lines";}parse(e,o,r){r.emitPluginCall(this.isAverage?"averageAbove":"totalAbove",0);}};var xf=chunkYBQOQTVL_cjs.c("LINE_REF"),Rf=chunkYBQOQTVL_cjs.c("SUM_RANGE_CALL"),Of=chunkYBQOQTVL_cjs.c("AVERAGE_RANGE_CALL");function ol(){return {name:"lines:line-ref",priority:80,startTokenTypes:["IDENT"],match(t,e){if(e>0&&t[e-1].type==="COLON"&&!(e>1&&t[e-2].type==="LINE_REF"))return null;let o=t[e];if(!o)return null;if(o.type==="IDENT"){let r=/^line(\d+)$/i.exec(o.value);if(r)return {consumed:1,replacement:[rl(r[1],o)],ruleName:"lines:line-ref"}}if(o.type==="IDENT"&&/^line$/i.test(o.value)){let r=t[e+1];if(r&&r.type==="NUMBER"&&/^\d+$/.test(r.value))return {consumed:2,replacement:[rl(r.value,o)],ruleName:"lines:line-ref"}}return null}}}function rl(t,e){return new chunk6EYKVQT3_cjs.a("LINE_REF",xf,t,t,e.offset,0,e.line,e.col)}function nl(){return {name:"lines:range-call",priority:80,shape:[{types:["IDENT"],values:["sum","total","average"]},{types:["LPAREN"]}],match(t,e){let o=t[e];if(!o||o.type!=="IDENT")return null;let r=o.value.toLowerCase();if(r!=="sum"&&r!=="total"&&r!=="average"||t[e+1]?.type!=="LPAREN")return null;let n=r==="average"?"AVERAGE_RANGE_CALL":"SUM_RANGE_CALL",i=r==="average"?Of:Rf;return {consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(n,i,o.value,o.value,o.offset,0,o.line,o.col)],ruleName:"lines:range-call"}}}}function uo(t,e){return t===void 0?chunkGJZIJK2Q_cjs.P("LINE_NOT_YET_EVALUATED",`Line ${e} has not been evaluated yet (forward reference, or out of range)`):t.type===12?chunkGJZIJK2Q_cjs.P("LINE_RESULT_PENDING",`Line ${e}'s result is still resolving`):t.type===13?chunkGJZIJK2Q_cjs.P("LINE_RESULT_ERROR",`Line ${e} has an error`):null}function be(t){return t?.getLineResult?null:chunkGJZIJK2Q_cjs.P("LINE_REF_NO_DOCUMENT","Cross-line references require a real document \u2014 not available outside one (e.g. evaluateExpression()'s single-expression path)")}function il(t,e){let o=be(e);if(o)return o;let r=e.lineIndex-1,n=e.getLineResult(r);return uo(n,r)??n}function al(t,e){let o=be(e);if(o)return o;let r=t[0].toNumber(),n=e.getLineResult(r);return uo(n,r)??n}function sl(t,e,o,r){let n=0,i=0,a,s=false,l=t<=e?1:-1;for(let c=t;l>0?c<=e:c>=e;c+=l){let f=o.getLineResult(c),T=uo(f,c);if(T)return T;if(f.type!==0&&f.type!==6)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_NON_NUMERIC",`Line ${c} is not a plain number or unit value \u2014 cannot include it in a sum/total/average range`);if(f.type===6){if(s=true,a===void 0)a=f.unit;else if(f.unit!==a)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_MIXED_UNITS",`Line ${c}'s unit (${f.unit}) doesn't match the range's first unit (${a}) \u2014 aggregating mixed units would silently misrepresent the result`)}n+=f.toNumber(),i++;}let u=r?n/i:n;return s?chunkGJZIJK2Q_cjs.u(u,a):chunkGJZIJK2Q_cjs.n(u)}function ml(t,e){let o=be(e);return o||sl(t[0].toNumber(),t[1].toNumber(),e,false)}function ll(t,e){let o=be(e);return o||sl(t[0].toNumber(),t[1].toNumber(),e,true)}function ul(t,e){let o=t.isLineBoundary;if(!o)return chunkGJZIJK2Q_cjs.P("LINE_REF_NO_DOCUMENT",'"above" aggregation requires a real document');let r=0,n=0,i,a=false;for(let l=t.lineIndex-1;l>=1&&!o(l);l--){let u=t.getLineResult(l),c=uo(u,l);if(c)return c;if(u.type!==0&&u.type!==6)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_NON_NUMERIC",`Line ${l} is not a plain number or unit value \u2014 cannot include it in "above" aggregation`);if(u.type===6){if(a=true,i===void 0)i=u.unit;else if(u.unit!==i)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_MIXED_UNITS",`Line ${l}'s unit (${u.unit}) doesn't match the range's unit (${i})`)}r+=u.toNumber(),n++;}if(n===0)return chunkGJZIJK2Q_cjs.P("LINE_RANGE_EMPTY","No lines above to aggregate (hit the top of the document, a blank line, or a heading immediately)");let s=e?r/n:r;return a?chunkGJZIJK2Q_cjs.u(s,i):chunkGJZIJK2Q_cjs.n(s)}function cl(t,e){let o=be(e);return o||ul(e,false)}function pl(t,e){let o=be(e);return o||ul(e,true)}var qn={name:"solve-lines",lexerVocabulary:{keywords:{prev:"PREV"}},phrases:{"total above":"TOTAL_ABOVE","sum above":"SUM_ABOVE","average above":"AVERAGE_ABOVE"},normalizerRules:[ol(),nl()],prefixParselets:{PREV:new mo,LINE_REF:new lo,SUM_RANGE_CALL:new Nt(false),AVERAGE_RANGE_CALL:new Nt(true),TOTAL_ABOVE:new De(false),SUM_ABOVE:new De(false),AVERAGE_ABOVE:new De(true)},pluginFunctions:{prev:il,lineRef:al,sumRange:ml,averageRange:ll,totalAbove:cl,averageAbove:pl}};var V=class{constructor(e){this.pluginFnName=e;this.category="Tables";}parse(e,o,r){let n=e.peek();if(!n||n.type!=="STRING")throw chunkGXO7TSXQ_cjs.c.parsing("TABLE_COLUMN_NAME_EXPECTED",`Expected a quoted column name after "... of column" but got ${n?`"${n.value}"`:"end of input"}`);let i=e.consume("STRING");for(;;){let a=e.peek();if(!a)break;if(a.type==="IN"){e.consume();continue}if(a.type==="IDENT"&&Cf.has(a.value.toLowerCase())){e.consume();continue}break}r.emitOpcode(13),r.emitString(i.value),r.emitPluginCall(this.pluginFnName,1);}},Cf=new Set(["the","table","above"]);function fl(t){return t.trimStart().startsWith("|")}function If(t){let e=t.trim();return e.length===0||!e.includes("-")||!e.includes("|")?false:/^[|\s:-]+$/.test(e)}function dl(t){let e=t.trim();e.startsWith("|")&&(e=e.slice(1)),e.endsWith("|")&&!e.endsWith("\\|")&&(e=e.slice(0,-1));let o=[],r="";for(let n=0;n<e.length;n++){let i=e[n];if(i==="\\"&&n+1<e.length&&e[n+1]==="|"){r+="|",n++;continue}if(i==="|"){o.push(r.trim()),r="";continue}r+=i;}return o.push(r.trim()),o}function hf(t){if(t===void 0)return null;let e=t.trim();if(e.length===0)return null;let o=e.replace(/,/g,"");if(!/^[+-]?(\d+(\.\d+)?|\.\d+)$/.test(o))return null;let r=Number.parseFloat(o);return Number.isFinite(r)?r:null}function El(t,e){let o=-1;for(let s=e-1;s>=1;s--){let l=t(s);if(l===void 0)break;if(fl(l)){o=s;break}}if(o===-1)return null;let r=o;for(;r-1>=1;){let s=t(r-1);if(s===void 0||!fl(s))break;r--;}let n=-1;for(let s=r;s<=o;s++)if(If(t(s))){n=s;break}if(n===-1||n===r)return null;let i=dl(t(n-1)),a=[];for(let s=n+1;s<=o;s++)a.push(dl(t(s)));return {header:i,rows:a}}function Tl(t,e){let o=e.trim().toLowerCase();for(let r=0;r<t.length;r++)if(t[r].trim().toLowerCase()===o)return r;return -1}function Nl(t,e){let o=[];for(let r of t.rows){let n=hf(r[e]);n!==null&&o.push(n);}return o}var co={TABLE_NO_DOCUMENT:"TABLE_NO_DOCUMENT",TABLE_NOT_FOUND:"TABLE_NOT_FOUND",TABLE_COLUMN_NOT_FOUND:"TABLE_COLUMN_NOT_FOUND",TABLE_COLUMN_NO_NUMERIC_CELLS:"TABLE_COLUMN_NO_NUMERIC_CELLS"};function po(t,e){let o=t.length;if(o===0)return 0;let r=e?o-1:o;if(r<=0)return 0;let n=t.reduce((i,a)=>i+a,0)/o;return t.reduce((i,a)=>i+(a-n)*(a-n),0)/r}function Sf(t,e){switch(t){case "sum":return e.reduce((o,r)=>o+r,0);case "average":return e.reduce((o,r)=>o+r,0)/e.length;case "min":return Math.min(...e);case "max":return Math.max(...e);case "count":return e.length;case "median":{let o=[...e].sort((n,i)=>n-i),r=Math.floor(o.length/2);return o.length%2===0?(o[r-1]+o[r])/2:o[r]}case "stdev":return Math.sqrt(po(e,false));case "sampleStdev":return Math.sqrt(po(e,true));case "variance":return po(e,false);case "sampleVariance":return po(e,true);case "spread":return Math.max(...e)-Math.min(...e);case "mode":{let o=new Map,r=e[0],n=0;for(let i of e){let a=(o.get(i)??0)+1;o.set(i,a),a>n&&(n=a,r=i);}return r}}}function $(t,e,o){let r=o?.getLineText;if(!r||o.lineIndex<1)return chunkGJZIJK2Q_cjs.P(co.TABLE_NO_DOCUMENT,"Reading a table column needs a real document, which the single-expression path (evaluateExpression) does not have");let n=El(r,o.lineIndex);if(!n)return chunkGJZIJK2Q_cjs.P(co.TABLE_NOT_FOUND,'No markdown table found above this line (a table row starts with "|", and needs a "|---|" separator under its header)');let i=Tl(n.header,e);if(i===-1){let s=n.header.map(l=>`"${l}"`).join(", ");return chunkGJZIJK2Q_cjs.P(co.TABLE_COLUMN_NOT_FOUND,`The table above has no column named "${e}". Its columns are: ${s}`)}let a=Nl(n,i);return t==="count"?chunkGJZIJK2Q_cjs.n(a.length):a.length===0?chunkGJZIJK2Q_cjs.P(co.TABLE_COLUMN_NO_NUMERIC_CELLS,`Column "${e}" has no plain-number cells to aggregate (currency and unit cells are not read yet)`):chunkGJZIJK2Q_cjs.n(Sf(t,a))}function W(t){let e=t[0];return e&&e.type===3&&typeof e.value=="string"?e.value:String(e?.value??"")}function yl(t,e){return $("sum",W(t),e)}function gl(t,e){return $("average",W(t),e)}function Pl(t,e){return $("min",W(t),e)}function _l(t,e){return $("max",W(t),e)}function Al(t,e){return $("count",W(t),e)}function xl(t,e){return $("median",W(t),e)}function Rl(t,e){return $("stdev",W(t),e)}function Ol(t,e){return $("sampleStdev",W(t),e)}function Cl(t,e){return $("variance",W(t),e)}function Il(t,e){return $("sampleVariance",W(t),e)}function hl(t,e){return $("spread",W(t),e)}function Sl(t,e){return $("mode",W(t),e)}var Zn={name:"solve-tables",phrases:{"sum of column":"TABLE_COLUMN_SUM","total of column":"TABLE_COLUMN_SUM","average of column":"TABLE_COLUMN_AVERAGE","mean of column":"TABLE_COLUMN_AVERAGE","min of column":"TABLE_COLUMN_MIN","minimum of column":"TABLE_COLUMN_MIN","max of column":"TABLE_COLUMN_MAX","maximum of column":"TABLE_COLUMN_MAX","count of column":"TABLE_COLUMN_COUNT","median of column":"TABLE_COLUMN_MEDIAN","standard deviation of column":"TABLE_COLUMN_STDEV","stdev of column":"TABLE_COLUMN_STDEV","sample standard deviation of column":"TABLE_COLUMN_SAMPLE_STDEV","variance of column":"TABLE_COLUMN_VARIANCE","sample variance of column":"TABLE_COLUMN_SAMPLE_VARIANCE","spread of column":"TABLE_COLUMN_SPREAD","mode of column":"TABLE_COLUMN_MODE"},prefixParselets:{TABLE_COLUMN_SUM:new V("TABLE_COLUMN_SUM"),TABLE_COLUMN_AVERAGE:new V("TABLE_COLUMN_AVERAGE"),TABLE_COLUMN_MIN:new V("TABLE_COLUMN_MIN"),TABLE_COLUMN_MAX:new V("TABLE_COLUMN_MAX"),TABLE_COLUMN_COUNT:new V("TABLE_COLUMN_COUNT"),TABLE_COLUMN_MEDIAN:new V("TABLE_COLUMN_MEDIAN"),TABLE_COLUMN_STDEV:new V("TABLE_COLUMN_STDEV"),TABLE_COLUMN_SAMPLE_STDEV:new V("TABLE_COLUMN_SAMPLE_STDEV"),TABLE_COLUMN_VARIANCE:new V("TABLE_COLUMN_VARIANCE"),TABLE_COLUMN_SAMPLE_VARIANCE:new V("TABLE_COLUMN_SAMPLE_VARIANCE"),TABLE_COLUMN_SPREAD:new V("TABLE_COLUMN_SPREAD"),TABLE_COLUMN_MODE:new V("TABLE_COLUMN_MODE")},pluginFunctions:{TABLE_COLUMN_SUM:yl,TABLE_COLUMN_AVERAGE:gl,TABLE_COLUMN_MIN:Pl,TABLE_COLUMN_MAX:_l,TABLE_COLUMN_COUNT:Al,TABLE_COLUMN_MEDIAN:xl,TABLE_COLUMN_STDEV:Rl,TABLE_COLUMN_SAMPLE_STDEV:Ol,TABLE_COLUMN_VARIANCE:Cl,TABLE_COLUMN_SAMPLE_VARIANCE:Il,TABLE_COLUMN_SPREAD:hl,TABLE_COLUMN_MODE:Sl}};var Ve=class{constructor(e){this.pluginFnName=e;this.category="Tags";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall(this.pluginFnName,1);}};function fo(t){return t===void 0?"":(t.text??t.value??"").toLowerCase()}var Ll={TOTAL_OF:"TAG_SUM",COUNT_OF:"TAG_COUNT",AVERAGE_OF:"TAG_AVERAGE"},Lf=new Set(["total","sum","count","average"]);function vl(t=80){return {name:"tags:aggregate",priority:t,shape:[{types:["TOTAL_OF","COUNT_OF","AVERAGE_OF","IDENT"]}],match(e,o){let r=e[o];if(r===void 0)return null;let n=Ll[r.type];if(n!==void 0){let i=e[o+1];return i?.type!=="TAG"?null:{consumed:2,replacement:[chunkZSLVLMO5_cjs.b(n,i.value??"",[r,i])],ruleName:"tags:aggregate"}}if(r.type==="IDENT"&&fo(r)==="sum"){let i=e[o+1],a=e[o+2];return fo(i)!=="of"||a?.type!=="TAG"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("TAG_SUM",a.value??"",[r,i,a])],ruleName:"tags:aggregate"}}return null}}}function kl(t=40){return {name:"tags:strip",priority:t,shape:[{types:["TAG"]}],match(e,o){if(e[o]?.type!=="TAG")return null;let r=e[o-1];return r!==void 0&&(Ll[r.type]!==void 0||fo(r)==="of"&&Lf.has(fo(e[o-2])))?null:{consumed:1,replacement:[],ruleName:"tags:strip"}}}}function vf(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function wl(t,e){if(e==="")return false;let r=new RegExp(`(?:^|[^0-9A-Za-z_])#${vf(e)}(?![0-9A-Za-z_-])`,"i").exec(t);if(r===null)return false;let n=r.index+r[0].indexOf("#");return t.slice(0,n).trim().length>0}function kf(t,e){return t===void 0?chunkGJZIJK2Q_cjs.P("LINE_NOT_YET_EVALUATED",`Line ${e} has not been evaluated yet`):t.type===12?chunkGJZIJK2Q_cjs.P("LINE_RESULT_PENDING",`Line ${e}'s result is still resolving`):t.type===13?chunkGJZIJK2Q_cjs.P("LINE_RESULT_ERROR",`Line ${e} has an error`):null}function Jn(t){return !t?.getLineResult||!t.getLineText?chunkGJZIJK2Q_cjs.P("TAG_NO_DOCUMENT","Category tag sums require a real document, not available outside one (e.g. evaluateExpression()'s single-expression path)"):null}function ei(t,e,o){let r=t.getLineText,n=t.getLineResult,i=t.isLineBoundary,a=e.toLowerCase(),s=0,l=0,u,c=false;for(let T=1;;T++){let N=r(T);if(N===void 0)break;if(T===t.lineIndex||i&&i(T)||!wl(N,a))continue;let E=n(T),P=kf(E,T);if(P)return P;if(o!=="count"){if(E.type!==0&&E.type!==6)return chunkGJZIJK2Q_cjs.P("TAG_NON_NUMERIC",`Line ${T}, tagged #${e}, is not a plain number or unit value.`);if(E.type===6){if(c=true,u===void 0)u=E.unit;else if(E.unit!==u)return chunkGJZIJK2Q_cjs.P("TAG_MIXED_UNITS",`Line ${T}'s unit (${E.unit}) doesn't match #${e}'s first unit (${u}), aggregating mixed units would misrepresent the result.`)}s+=E.toNumber();}l++;}if(o==="count")return chunkGJZIJK2Q_cjs.n(l);if(l===0)return chunkGJZIJK2Q_cjs.P("TAG_EMPTY",`No lines are tagged #${e}.`);let f=o==="average"?s/l:s;return c?chunkGJZIJK2Q_cjs.u(f,u):chunkGJZIJK2Q_cjs.n(f)}function Ml(t,e){let o=Jn(e);return o||ei(e,String(t[0].value),"sum")}function Bl(t,e){let o=Jn(e);return o||ei(e,String(t[0].value),"average")}function Ul(t,e){let o=Jn(e);return o||ei(e,String(t[0].value),"count")}var ti={name:"solve-tags",normalizerRules:[vl(),kl()],prefixParselets:{TAG_SUM:new Ve("sum"),TAG_AVERAGE:new Ve("average"),TAG_COUNT:new Ve("count")},pluginFunctions:{sum:Ml,average:Bl,count:Ul}};var yt=class{constructor(e){this.fn=e;this.category="Payroll";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall(this.fn,1);}},gt=class{constructor(e){this.fn=e;this.category="Payroll";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall(this.fn,1);}};function wf(t,e){if(t<=e.personalAllowanceTaperFrom)return e.personalAllowance;let o=(t-e.personalAllowanceTaperFrom)/2;return Math.max(0,e.personalAllowance-o)}function Mf(t,e){let o=Math.max(0,t-wf(t,e)),r=Math.min(o,e.basicRateLimit),n=Math.min(Math.max(0,o-e.basicRateLimit),e.higherRateLimit-e.basicRateLimit),i=Math.max(0,o-e.higherRateLimit);return r*e.basicRate+n*e.higherRate+i*e.additionalRate}function Bf(t,e){if(t<=e.niPrimaryThreshold)return 0;let o=Math.min(t,e.niUpperEarningsLimit)-e.niPrimaryThreshold,r=Math.max(0,t-e.niUpperEarningsLimit);return o*e.niMainRate+r*e.niUpperRate}function ri(t,e){return t-Mf(t,e)-Bf(t,e)}var Uf=1920;function Dl(t){return t/Uf}var oi={personalAllowance:12570,personalAllowanceTaperFrom:1e5,basicRateLimit:37700,higherRateLimit:125140,basicRate:.2,higherRate:.4,additionalRate:.45,niPrimaryThreshold:12570,niUpperEarningsLimit:50270,niMainRate:.08,niUpperRate:.02};var ni=oi;function ii(t,e){let o=e(t.toNumber());return t.type===6?chunkGJZIJK2Q_cjs.u(o,t.unit):chunkGJZIJK2Q_cjs.n(o)}var ai={name:"solve-payroll",phrases:{"take home on":"TAKE_HOME_ON","hourly for":"HOURLY_FOR","after tax":"AFTER_TAX","salary after tax":"AFTER_TAX","per month after tax":"AFTER_TAX_MONTHLY","monthly after tax":"AFTER_TAX_MONTHLY","salary per month after tax":"AFTER_TAX_MONTHLY"},prefixParselets:{TAKE_HOME_ON:new yt("payrollTakeHome"),HOURLY_FOR:new yt("payrollHourly")},infixParselets:{AFTER_TAX:new gt("payrollTakeHome"),AFTER_TAX_MONTHLY:new gt("payrollTakeHomeMonthly")},pluginFunctions:{payrollTakeHome:t=>ii(t[0],e=>ri(e,ni)),payrollTakeHomeMonthly:t=>ii(t[0],e=>ri(e,ni)/12),payrollHourly:t=>ii(t[0],Dl)},tokenCategories:{TAKE_HOME_ON:"function",HOURLY_FOR:"function",AFTER_TAX:"operator",AFTER_TAX_MONTHLY:"operator"}};function Df(t){return {category:"Shopping",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitPluginCall(t,2);}}}function bf(t){let e=t[0],o=t[1],r=e.toNumber(),n=o.toNumber();if(e.type===6||o.type===6){if(e.type!==6||o.type!==6||e.unit===void 0||o.unit===void 0)return chunkGJZIJK2Q_cjs.P("VS_INCOMPARABLE","vs: compare two amounts of the same kind");if(e.unit!==o.unit){if(!chunkZKFCKAIX_cjs.d(o.unit,e.unit))return chunkGJZIJK2Q_cjs.P("VS_INCOMPARABLE",`vs: ${e.unit} and ${o.unit} are not the same kind of thing`);n=chunkZKFCKAIX_cjs.e(n,o.unit,e.unit);}}if(Math.abs(r-n)<=Math.max(Math.abs(r),Math.abs(n))*1e-9)return chunkGJZIJK2Q_cjs.t("the same");let i=r<n,a=Math.min(r,n),s=Math.max(r,n),l=Math.round((s-a)/s*100);return chunkGJZIJK2Q_cjs.t(`the ${i?"first":"second"} is cheaper, ${l}% less`)}var si={name:"solve-shopping",lexerVocabulary:{keywords:{vs:"VS_COMPARE",versus:"VS_COMPARE"}},infixParselets:{VS_COMPARE:Df("shoppingCompare")},pluginFunctions:{shoppingCompare:bf},tokenCategories:{VS_COMPARE:"operator"}};var Eo=class{constructor(){this.category="operator";this.bindingPower=chunkZDJTDFTR_cjs.a.Uncertainty;}parse(e,o,r,n){e.parseExpression(this.bindingPower,n),n.emitOpcode(28);}};function Fl(t=90){return {name:"uncertainty:ascii-plus-minus",priority:t,shape:[{types:["PLUS"]},{types:["SLASH"]}],match(e,o){let r=e[o];if(r?.type!=="PLUS")return null;let n=e[o+1];if(n?.type!=="SLASH")return null;let i=e[o+2];return i?.type!=="MINUS"?null:{consumed:3,replacement:[chunkZSLVLMO5_cjs.b("PLUS_MINUS","\xB1",[r,n,i])],ruleName:"uncertainty:ascii-plus-minus"}}}}var mi={name:"solve-uncertainty",infixParselets:{PLUS_MINUS:new Eo},normalizerRules:[Fl()]};var Hl=1e-9,Gl=1e9,Vf=100,Ff=1e-9,Hf=1e-9,Gf=1e-12,zf=1e-9,To="goalseek";function zl(t,e){let o=e?.evaluateLineWithBinding,r=e?.getLineReads;if(!o||!r)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NO_DOCUMENT","Goal seek only works inside a document, since it re-runs another line. The single-expression entry point has no document to solve against.");let n=t[0].toNumber(),i=typeof t[1].value=="string"?t[1].value:String(t[1].value),a=t[2];if(a.type!==0&&a.type!==6)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC",`Goal seek's target must be a number, as in "solve line ${n} for ${i} = 900".`);let s=a.toNumber();if(!Number.isFinite(s))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC","Goal seek's target is not a finite number.");let l=r(n);if(l===void 0)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_LINE_NOT_READY",`Line ${n} has no evaluated expression to solve (forward reference, out of range, or not an expression).`);if(!l.includes(i))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_VARIABLE_NOT_USED",`Line ${n} does not use ${i}, so changing ${i} cannot move its result toward ${s}.`);let u=o(n,i,chunkGJZIJK2Q_cjs.K(chunkFDKTESBC_cjs.q(i)),true);if(u.type===9){let f=Kf(u.value,s,i);if(f!==null)return chunkGJZIJK2Q_cjs.n(f)}let c=e.goalSeekMaxIterations??Vf;return $f(o,n,i,s,c)}function Kf(t,e,o){let r=chunkFDKTESBC_cjs.p(chunkFDKTESBC_cjs.d(e)),n;try{n=chunkQQHHZPEW_cjs.d(t,r,o);}catch{return null}if(n.kind!=="roots")return null;let i=[];for(let l of n.exact){let u=chunkFDKTESBC_cjs.Q(l);if(u.kind==="const"){let c=chunkFDKTESBC_cjs.e(u.value);Number.isFinite(c)&&i.push(c);}}for(let l of n.approximate)Math.abs(l.im)<=zf&&Number.isFinite(l.re)&&i.push(l.re);if(i.length===0)return null;let a=i.filter(l=>l>=Hl&&l<=Gl),s=a.length>0?a:i;return s.sort((l,u)=>Math.abs(l)-Math.abs(u)),s[0]}function $f(t,e,o,r,n){let i=N=>{let E=t(e,o,chunkGJZIJK2Q_cjs.n(N),false);if(E.type===13)return {error:E};if(E.type!==0&&E.type!==6)return {error:chunkGJZIJK2Q_cjs.P("GOAL_SEEK_TARGET_NOT_NUMERIC",`Line ${e} did not produce a number when ${o} was set to ${N}, so goal seek cannot compare it to the target.`)};let P=E.toNumber();return Number.isFinite(P)?{value:P}:{error:chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NON_FINITE",`Line ${e}'s result is not finite when ${o} is ${N}.`)}},a=Hl,s=Gl,l=i(a);if("error"in l)return l.error;let u=i(s);if("error"in u)return u.error;let c=Math.max(Ff,Math.abs(r)*Hf),f=l.value-r,T=u.value-r;if(Math.abs(f)<=c)return chunkGJZIJK2Q_cjs.n(a);if(Math.abs(T)<=c)return chunkGJZIJK2Q_cjs.n(s);if(Math.sign(f)===Math.sign(T))return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_NO_SOLUTION",`No value of ${o} between ${a} and ${s} makes line ${e} equal ${r}: across that whole range its result stays on one side of the target.`);for(let N=0;N<n;N++){let E=(a+s)/2,P=i(E);if("error"in P)return P.error;let R=P.value-r;if(Math.abs(R)<=c)return chunkGJZIJK2Q_cjs.n(E);if(s-a<=Gf)return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_DID_NOT_CONVERGE",`Goal seek narrowed ${o} to a single point near ${E} without line ${e} reaching ${r}: the relationship jumps across the target rather than passing through it.`);Math.sign(R)===Math.sign(f)?(a=E,f=R):s=E;}return chunkGJZIJK2Q_cjs.P("GOAL_SEEK_DID_NOT_CONVERGE",`Goal seek did not bring line ${e} within tolerance of ${r} by varying ${o} in ${n} steps.`)}var No=class{constructor(){this.category="GoalSeek";}parse(e,o,r){let n=e.peek();if(!n||n.type!=="LINE_REF")throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_SYNTAX",'Goal seek reads "solve line N for <var> = <target>", for example "solve line 4 for rate = 900".',{found:n?.type??"end of input"});e.consume();let i=parseInt(n.value,10),a=e.peek();if(!(!!a&&(a.type==="FOR_DURATION"||a.type==="IDENT"&&a.value.toLowerCase()==="for")))throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_SYNTAX",'Goal seek reads "solve line N for <var> = <target>". Expected "for" after the line reference.',{found:a?.type??"end of input"});e.consume();let l=e.peek();if(!l||l.type!=="IDENT"&&l.type!=="UNIT")throw chunkGXO7TSXQ_cjs.c.parsing("GOAL_SEEK_REQUIRES_VARIABLE_NAME",'Goal seek needs the name of the variable to vary here, as in "solve line 4 for rate = 900".',{found:l?.type??"end of input"});e.consume(),e.consume("EQUALS"),r.emitOpcode(10),r.emitNumber(i),r.emitOpcode(13),r.emitString(l.value),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),r.emitPluginCall(To,3);}};var Wf=chunkYBQOQTVL_cjs.c("GOAL_SEEK");function Kl(t=75){return {name:"goalseek:solve-line",priority:t,shape:[{types:["IDENT"],values:["solve"]},{types:["LINE_REF"]}],match(e,o){if(o>0&&e[o-1].type==="COLON")return null;let r=e[o];return !r||r.type!=="IDENT"||r.value.toLowerCase()!=="solve"||e[o+1]?.type!=="LINE_REF"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("GOAL_SEEK",Wf,r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"goalseek:solve-line"}}}}var li={name:"solve-goalseek",normalizerRules:[Kl()],prefixParselets:{GOAL_SEEK:new No},pluginFunctions:{[To]:zl}};var yo=class{constructor(){this.category="Colour";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("colour",1);}};var Ne={COLOUR_INVALID:"COLOUR_INVALID",COLOUR_EXPECTED_COLOUR:"COLOUR_EXPECTED_COLOUR",COLOUR_BAD_ARGUMENTS:"COLOUR_BAD_ARGUMENTS"};function B(t){return t&&t.type===14?t.value:null}function D(t){if(!t)return 0;let e=t.toNumber();return t.type===5?e:e>1?e/100:e}function J(t,e){return chunkGJZIJK2Q_cjs.P(Ne.COLOUR_BAD_ARGUMENTS,`${t}(...) expects ${e}`)}function Q(t){return chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,`${t}(...) expects a colour as its first argument`)}function $l(t){let e=t[0];if(!e||e.type!==3||typeof e.value!="string")return J("color",'a string, e.g. color("#ff0000") or color("red")');let o=chunk5TVI2UPZ_cjs.c(e.value);return o?chunkGJZIJK2Q_cjs.G(o):chunkGJZIJK2Q_cjs.P(Ne.COLOUR_INVALID,`"${e.value}" is not a hex colour (#rgb, #rgba, #rrggbb, #rrggbbaa) or a CSS colour name`)}function Yf(t){return t.length!==3?J("rgb","three numbers: rgb(red, green, blue)"):chunkGJZIJK2Q_cjs.G({r:chunk5TVI2UPZ_cjs.a(t[0].toNumber()),g:chunk5TVI2UPZ_cjs.a(t[1].toNumber()),b:chunk5TVI2UPZ_cjs.a(t[2].toNumber()),a:1,format:"rgb"})}function jf(t){return t.length!==4?J("rgba","four numbers: rgba(red, green, blue, alpha)"):chunkGJZIJK2Q_cjs.G({r:chunk5TVI2UPZ_cjs.a(t[0].toNumber()),g:chunk5TVI2UPZ_cjs.a(t[1].toNumber()),b:chunk5TVI2UPZ_cjs.a(t[2].toNumber()),a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"rgba"})}function Xf(t){if(t.length!==3)return J("hsl","three values: hsl(hue, saturation%, lightness%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.e(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hsl"})}function Qf(t){if(t.length!==4)return J("hsla","four values: hsla(hue, saturation%, lightness%, alpha)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.e(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"hsla"})}function ye(t,e){return o=>{let r=B(o[0]);return r?o.length<2?J(t,`a colour and an amount, e.g. ${t}(#3366cc, 20%)`):chunkGJZIJK2Q_cjs.G(e(r,D(o[1]))):Q(t)}}var qf=ye("lighten",chunk5TVI2UPZ_cjs.j),Zf=ye("darken",chunk5TVI2UPZ_cjs.k),Jf=ye("saturate",chunk5TVI2UPZ_cjs.l),Wl=ye("desaturate",chunk5TVI2UPZ_cjs.m);function ui(t){let e=B(t[0]);return e?t.length<2?J("rotate","a colour and a hue angle in degrees, e.g. rotate(#ff0000, 90)"):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.n(e,t[1].toNumber())):Q("rotate")}function ed(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.o(e)):Q("complement")}function Yl(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.p(e)):Q("grayscale")}function jl(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.q(e,t.length>1?D(t[1]):1)):Q("invert")}function td(t){let e=B(t[0]),o=B(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"mix(...) expects two colours to blend"):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.r(e,o,t.length>2?D(t[2]):.5))}function ci(t){let e=B(t[0]);return e?t.length<2?chunkGJZIJK2Q_cjs.n(e.a):chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.s(e,D(t[1]))):Q("alpha")}function rd(t){let e=B(t[0]),o=B(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"contrast(...) expects two colours"):chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.i(e,o))}function od(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.h(e)):Q("luminance")}function Fe(t,e){return o=>{let r=B(o[0]);return r?chunkGJZIJK2Q_cjs.n(e(r)):Q(t)}}var nd=Fe("red",t=>t.r),id=Fe("green",t=>t.g),ad=Fe("blue",t=>t.b),sd=Fe("hue",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).h),md=Fe("saturation",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).s*100),ld=Fe("lightness",t=>chunk5TVI2UPZ_cjs.d(t.r,t.g,t.b).l*100);function Xl(t){if(t.length!==3)return J("hsv","three values: hsv(hue, saturation%, value%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.t(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hex"})}function ud(t){if(t.length!==4)return J("hsva","four values: hsva(hue, saturation%, value%, alpha)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.t(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:chunk5TVI2UPZ_cjs.b(D(t[3])),format:"hex"})}function cd(t){if(t.length!==3)return J("hwb","three values: hwb(hue, whiteness%, blackness%)");let{r:e,g:o,b:r}=chunk5TVI2UPZ_cjs.u(t[0].toNumber(),D(t[1]),D(t[2]));return chunkGJZIJK2Q_cjs.G({r:e,g:o,b:r,a:1,format:"hex"})}var pd=ye("tint",chunk5TVI2UPZ_cjs.v),fd=ye("shade",chunk5TVI2UPZ_cjs.w),dd=ye("tone",chunk5TVI2UPZ_cjs.x);function Ed(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.y(e)):Q("isdark")}function Td(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.L(!chunk5TVI2UPZ_cjs.y(e)):Q("islight")}function pi(t){let e=B(t[0]);return e?chunkGJZIJK2Q_cjs.G(chunk5TVI2UPZ_cjs.z(e)):Q("readable")}function Nd(t){if(!t)return chunk5TVI2UPZ_cjs.A.aa;if(t.type===0)return t.toNumber();if(t.type===3){let e=t.value.trim().toLowerCase();if(e==="aaa")return chunk5TVI2UPZ_cjs.A.aaa;if(e==="aa large"||e==="aa-large"||e==="large")return chunk5TVI2UPZ_cjs.A.aaLarge;if(e==="aaa large"||e==="aaa-large")return chunk5TVI2UPZ_cjs.A.aaaLarge}return chunk5TVI2UPZ_cjs.A.aa}function yd(t){let e=B(t[0]),o=B(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"iscontrastcompliant(...) expects two colours"):chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.i(e,o)>=Nd(t[2]))}function Ql(t){let e=B(t[0]),o=B(t[1]);return !e||!o?chunkGJZIJK2Q_cjs.P(Ne.COLOUR_EXPECTED_COLOUR,"wcaglevel(...) expects two colours"):chunkGJZIJK2Q_cjs.t(chunk5TVI2UPZ_cjs.B(e,o))}var ge={color:$l,colour:$l,rgb:Yf,rgba:jf,hsl:Xf,hsla:Qf,lighten:qf,darken:Zf,saturate:Jf,desaturate:Wl,desat:Wl,rotate:ui,spin:ui,adjusthue:ui,complement:ed,grayscale:Yl,greyscale:Yl,invert:jl,mix:td,alpha:ci,opacity:ci,fade:ci,contrast:rd,luminance:od,red:nd,green:id,blue:ad,hue:sd,saturation:md,lightness:ld,hsv:Xl,hsb:Xl,hsva:ud,hwb:cd,tint:pd,shade:fd,tone:dd,negate:jl,isdark:Ed,islight:Td,readable:pi,contrastcolor:pi,contrastcolour:pi,iscontrastcompliant:yd,wcaglevel:Ql,wcag:Ql};var go=class{constructor(){this.category="Colour";}parse(e,o,r){let n=o.value.toLowerCase();if(ge[n]===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_COLOUR_FUNCTION",`Unknown colour function: ${n}`,{functionName:n});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var ql=new Set(Object.keys(ge));function Zl(t=80){return {name:"colour:call",priority:t,shape:[{types:["IDENT"],values:[...ql]},{types:["LPAREN"]}],match(e,o){let r=e[o];if(!r||r.type!=="IDENT")return null;let n=r.value.toLowerCase();return !ql.has(n)||e[o+1]?.type!=="LPAREN"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("COLOUR_CALL",chunkYBQOQTVL_cjs.c("COLOUR_CALL"),r.value,r.value,r.offset,0,r.line,r.col)],ruleName:"colour:call"}}}}var Po=t=>e=>{if(e.type!==14)return e;let o=e.value;return chunkGJZIJK2Q_cjs.G({r:o.r,g:o.g,b:o.b,a:o.a,format:t})},gd=Object.keys(ge).map(t=>({label:t,category:"function",detail:"colour"})),fi={name:"solve-colour",prefixParselets:{HEX_COLOUR:new yo,COLOUR_CALL:new go},normalizerRules:[Zl()],pluginFunctions:ge,asConverters:{rgb:Po("rgb"),rgba:Po("rgba"),hsl:Po("hsl"),hsla:Po("hsla")},completionItems:gd};var di=32;function Pd(t){if(t.hasSymbolic||t.rows!==1&&t.cols!==1)return null;let e=[];for(let o of t.data){if(typeof o!="number"||!Number.isFinite(o))return null;e.push(o);}return e}function _d(t){let e=t.max-t.min+1,o=Math.min(e,di),r=[];for(let n=0;n<o;n++)r.push(t.min+Math.round(n*(e-1)/(o-1)));return r}function Ad(t,e){if(t.length<=e)return [...t];let o=[];for(let r=0;r<e;r++)o.push(t[Math.round(r*(t.length-1)/(e-1))]);return o}function Jl(t){let e=null;if(t.type===7)e=Pd(t.value);else if(t.type===8){let a=t.value;e=a.max-a.min+1>=2?_d(a):null;}if(!e||e.length<2)return null;let o=Ad(e,di),r=Math.min(...e),n=Math.max(...e),i=e.length<=di?`[${e.join(", ")}]`:`sparkline of ${e.length} values`;return {kind:"sparkline",points:o.map((a,s)=>[s,a]),label:i,domain:[0,o.length-1],range:[r,n]}}var _o=class{constructor(){this.category="Plot";}parse(e,o,r){let n=xd(e),i=new chunkZDJTDFTR_cjs.d(r.pluginIndexMap);e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,i),e.setBuilder(r);let a=i.build();if(a.hasAsync)throw chunkGXO7TSXQ_cjs.c.parsing("PLOT_EXPR_MUST_BE_SYNCHRONOUS","a plot expression must be synchronous (no weather, stocks or currency calls).");e.consume("FROM"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r),e.consume("TO"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,r);let s=r.emitAnonymousBody(["x"],a);r.emitOpcode(160),r.emitIndex(s),r.emitString(n);}};function xd(t){let e=[];for(let n=0;;n++){let i=t.peekAt(n);if(!i||i.type==="FROM")break;e.push(i);}if(e.length===0)return "";let o=e[0].offset,r="";for(let n of e){let i=n.offset-o;for(;r.length<i;)r+=" ";r+=n.text??n.value??"";}return r.trim()}var tu="PLOT",Rd=chunkYBQOQTVL_cjs.c(tu),eu=new Set(["NUMBER","IDENT","FUNC","UNIT","LPAREN","PI","E"]);function ru(t=80){let e="plot:plot-clause";return {name:e,priority:t,shape:[{types:["IDENT"],values:["plot"]},{types:[...eu]}],match(o,r){let n=o[r];if(!n||n.type!=="IDENT"||(n.value??"").toLowerCase()!=="plot"||o[r-1]?.type==="COLON")return null;let i=o[r+1];return !i||!eu.has(i.type)?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a(tu,Rd,n.value,n.value,n.offset,0,n.line,n.col)],ruleName:e}}}}var Ei={name:"solve-chart",asConverters:{sparkline:t=>{let e=Jl(t);return e?chunkGJZIJK2Q_cjs.I(e):chunkGJZIJK2Q_cjs.P("SPARKLINE_NOT_A_SERIES",'"as sparkline" expects a numeric vector or a range, with at least two values')}},prefixParselets:{PLOT:new _o},normalizerRules:[ru()],tokenCategories:{PLOT:"keyword"}};var Pt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Ti(t){let e=new TextEncoder().encode(t),o="";for(let r=0;r<e.length;r+=3){let n=e[r],i=r+1<e.length?e[r+1]:0,a=r+2<e.length?e[r+2]:0;o+=Pt[n>>2],o+=Pt[(n&3)<<4|i>>4],o+=r+1<e.length?Pt[(i&15)<<2|a>>6]:"=",o+=r+2<e.length?Pt[a&63]:"=";}return o}function Ni(t){let e=t.replace(/\s+/g,"");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e))return null;let o=e.replace(/=+$/,""),r=[],n=0,i=0;for(let a of o){let s=Pt.indexOf(a);if(s<0)return null;i=i<<6|s,n+=6,n>=8&&(n-=8,r.push(i>>n&255));}try{return new TextDecoder("utf-8",{fatal:!0}).decode(new Uint8Array(r))}catch{return null}}function ou(t){return encodeURIComponent(t)}function nu(t){try{return decodeURIComponent(t)}catch{return null}}function iu(t){return Array.from(new TextEncoder().encode(t)).map(e=>e.toString(16).padStart(2,"0")).join(" ")}function yi(t){let e=t.trim().split(/[\s,]+/).filter(r=>r.length>0),o=[];for(let r of e){if(!/^[0-9a-fA-F]{1,2}$/.test(r))return null;o.push(parseInt(r,16));}try{return new TextDecoder("utf-8",{fatal:!0}).decode(new Uint8Array(o))}catch{return null}}function Od(t){let e=t.replace(/-/g,"+").replace(/_/g,"/"),o=e.length%4;return o===0?e:e+"=".repeat(4-o)}function gi(t){let e=t.trim().split(".");if(e.length<2||e[1]==="")return null;let o=Ni(Od(e[1]));if(o===null)return null;try{let r=JSON.parse(o);return r===null||typeof r!="object"||Array.isArray(r)?null:JSON.stringify(r)}catch{return null}}function Pi(t){let e=t.trim().replace(/^\?/,"");if(e==="")return "{}";let o=Object.create(null);for(let r of e.split("&")){if(r==="")continue;let n=r.indexOf("="),i=n===-1?r:r.slice(0,n),a=n===-1?"":r.slice(n+1);try{o[decodeURIComponent(i.replace(/\+/g," "))]=decodeURIComponent(a.replace(/\+/g," "));}catch{return null}}return JSON.stringify(o)}var Ao=class{constructor(){this.category="Encoding";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){let i=(r.value??"").replace(/^from\s+/i,"").toLowerCase();n.emitOpcode(13),n.emitString(i),n.emitPluginCall("fromEncoding",2);}};var He=class{constructor(e){this.fn=e;this.category="Encoding";}parse(e,o,r){e.consume("LPAREN"),e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),e.consume("RPAREN"),r.emitPluginCall(this.fn,1);}};function Ro(t){return t.type===3?t.value:null}function xo(t,e){return o=>{let r=Ro(o);return r===null?chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",`"as ${t}" expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(r))}}var Cd={base64:Ni,url:nu,"hex bytes":yi,hexbytes:yi,jwt:gi,query:Pi},_i={name:"solve-encoding",phrases:{"hex bytes":"CONVERTER_NAME","from base64":"FROM_ENCODING","from url":"FROM_ENCODING","from hex bytes":"FROM_ENCODING","from jwt":"FROM_ENCODING","from query":"FROM_ENCODING"},asConverters:{base64:xo("base64",Ti),url:xo("url",ou),"hex bytes":xo("hex bytes",iu)},infixParselets:{FROM_ENCODING:new Ao},prefixParselets:{BASE64_FN:new He("base64"),JWT_FN:new He("jwt"),QUERY_FN:new He("query")},callFusions:{base64:"BASE64_FN",jwt:"JWT_FN",query:"QUERY_FN"},pluginFunctions:{base64:t=>xo("base64",Ti)(t[0]),jwt:t=>{let e=Ro(t[0]);if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",'jwt(...) expects text (a "quoted string")');let o=gi(e);return o===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED","jwt(...): the input is not a valid JSON Web Token"):chunkGJZIJK2Q_cjs.t(o)},query:t=>{let e=Ro(t[0]);if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",'query(...) expects text (a "quoted string")');let o=Pi(e);return o===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED","query(...): the input is not a valid query string"):chunkGJZIJK2Q_cjs.t(o)},fromEncoding:t=>{let e=Ro(t[0]),o=String(t[1].value??"");if(e===null)return chunkGJZIJK2Q_cjs.P("ENCODING_EXPECTED_TEXT",`"from ${o}" expects text (a "quoted string")`);let r=Cd[o];if(!r)return chunkGJZIJK2Q_cjs.P("UNKNOWN_ENCODING",`"from ${o}" is not a known encoding (try base64, url or hex bytes)`);let n=r(e);return n===null?chunkGJZIJK2Q_cjs.P("ENCODING_DECODE_FAILED",`"from ${o}": the input is not valid ${o}`):chunkGJZIJK2Q_cjs.t(n)}},tokenCategories:{BASE64_FN:"function",JWT_FN:"function",QUERY_FN:"function"}};var Oo=class{constructor(){this.category="IP";}parse(e,o,r){r.emitOpcode(13),r.emitString(o.value),r.emitPluginCall("ipLiteral",1);}};var Ge=class{constructor(e){this.pluginFn=e;this.category="IP";}parse(e,o,r){let n=e.peek(),i=e.peekAt(1);n?.type==="SLASH"&&i?.type==="NUMBER"?(e.consume(),e.consume(),r.emitOpcode(13),r.emitString(`|${i.value}`),r.emitPluginCall("ipLiteral",1)):e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall(this.pluginFn,1);}};var au="IP_CIDR",Id=chunkYBQOQTVL_cjs.c(au),hd=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\/\d{1,2})?/,Sd=8;function su(t=72){let e="ip:ip-cidr-literal";return {name:e,priority:t,shape:[{types:["NUMBER"]}],match(o,r){let n=o[r];if(!n||n.type!=="NUMBER"||n.sourceEnd!==void 0||!/^\d{1,3}\./.test(n.text??""))return null;let i=n.text??"",a=n.offset+i.length,s=[n];for(let E=r+1;E<o.length&&s.length<Sd;E++){let P=o[E];if(P.sourceEnd!==void 0||P.offset!==a||P.type!=="NUMBER"&&P.type!=="SLASH")break;i+=P.text??"",a=P.offset+(P.text?.length??0),s.push(P);}let l=hd.exec(i);if(l===null)return null;let u=chunk5TVI2UPZ_cjs.C(l[0]);if(u===null||u.addr===void 0)return null;let c=0,f=0;for(let E of s)if(f+=E.text?.length??0,c++,f>=l[0].length)break;if(f!==l[0].length)return null;let T=`${u.addr}|${u.prefix??""}`,N=new chunk6EYKVQT3_cjs.a(au,Id,T,l[0],n.offset,0,n.line,n.col,n.offset+l[0].length);return {consumed:c,replacement:[N],ruleName:e}}}}function _t(t,e){return t.type===17?t.value:chunkGJZIJK2Q_cjs.P("IP_EXPECTED",`"${e}" expects an IP address or subnet (e.g. 192.168.1.0/24)`)}function mu(t){let[e,o]=String(t[0].value??"").split("|"),r={...e!==""?{addr:Number(e)}:{},...o!==""?{prefix:Number(o)}:{}};return chunkGJZIJK2Q_cjs.J(r)}function lu(t){let e=_t(t[0],"hosts in");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NO_PREFIX",'"hosts in" needs a subnet with a prefix, e.g. 192.168.1.0/24'):chunkGJZIJK2Q_cjs.n(chunk5TVI2UPZ_cjs.F(e.prefix))}function uu(t){let e=_t(t[0],"netmask of");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NO_PREFIX",'"netmask of" needs a prefix, e.g. /24 or 192.168.1.0/24'):chunkGJZIJK2Q_cjs.J({addr:chunk5TVI2UPZ_cjs.E(e.prefix)})}function cu(t){let e=_t(t[0],"broadcast of");return e instanceof chunkGJZIJK2Q_cjs.m?e:e.addr===void 0||e.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_NEEDS_ADDRESS_AND_PREFIX",'"broadcast of" needs an address and a prefix, e.g. 192.168.1.0/24'):chunkGJZIJK2Q_cjs.J({addr:chunk5TVI2UPZ_cjs.G(e.addr,e.prefix)})}function pu(t){let e=_t(t[0],"in");if(e instanceof chunkGJZIJK2Q_cjs.m)return e;let o=_t(t[1],"in");return o instanceof chunkGJZIJK2Q_cjs.m?o:e.addr===void 0?chunkGJZIJK2Q_cjs.P("IP_EXPECTED_ADDRESS",'"in" expects an address on the left'):o.addr===void 0||o.prefix===void 0?chunkGJZIJK2Q_cjs.P("IP_EXPECTED_BLOCK",'"in" expects a subnet on the right, e.g. 10.0.0.0/8'):chunkGJZIJK2Q_cjs.L(chunk5TVI2UPZ_cjs.H(e.addr,o.addr,o.prefix))}function fu(t){if(t.type===17){let e=t.value;return chunkGJZIJK2Q_cjs.n(e.addr??0)}return chunkGJZIJK2Q_cjs.n(Math.trunc(t.toNumber()))}var Ai={name:"solve-ip",phrases:{"hosts in":"HOSTS_IN","netmask of":"NETMASK_OF","broadcast of":"BROADCAST_OF"},prefixParselets:{IP_CIDR:new Oo,HOSTS_IN:new Ge("hostsIn"),NETMASK_OF:new Ge("netmaskOf"),BROADCAST_OF:new Ge("broadcastOf")},normalizerRules:[su()],pluginFunctions:{ipLiteral:mu,hostsIn:lu,netmaskOf:uu,broadcastOf:cu,ipInCidr:pu},asConverters:{int:fu},tokenCategories:{IP_CIDR:"number",HOSTS_IN:"keyword",NETMASK_OF:"keyword",BROADCAST_OF:"keyword"}};var At=[{mark:.25,celsius:110,written:"1/4"},{mark:.5,celsius:120,written:"1/2"},{mark:1,celsius:140,written:"1"},{mark:2,celsius:150,written:"2"},{mark:3,celsius:170,written:"3"},{mark:4,celsius:180,written:"4"},{mark:5,celsius:190,written:"5"},{mark:6,celsius:200,written:"6"},{mark:7,celsius:220,written:"7"},{mark:8,celsius:230,written:"8"},{mark:9,celsius:240,written:"9"}],Ld=10;function du(t){return At.find(e=>e.mark===t)?.celsius??null}function Eu(t){let e=null,o=Number.POSITIVE_INFINITY;for(let r of At){let n=Math.abs(r.celsius-t);n<o&&(e=r,o=n);}return e!==null&&o<=Ld?e:null}function xi(){return {coldest:At[0],hottest:At[At.length-1]}}var vd=chunkYBQOQTVL_cjs.c("GAS_MARK");function Tu(t=72){let e="cooking:gas-mark";return {name:e,priority:t,shape:[{types:["CONVERTER_NAME","IDENT"],values:["gas mark","gas"]},{types:["NUMBER","BIGINT"]}],match(o,r){let n=o[r];if(n===void 0)return null;let i=(n.value??"").toLowerCase();if(i!=="gas mark"&&i!=="gas"||n.type!=="CONVERTER_NAME"&&n.type!=="IDENT")return null;let a=o[r+1];return a?.type!=="NUMBER"&&a?.type!=="BIGINT"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("GAS_MARK",vd,i,n.text??i,n.offset,0,n.line,n.col)],ruleName:e}}}}var kd=chunkYBQOQTVL_cjs.c("SCALE_SERVINGS"),wd=new Set(["servings","serving","serves","people","portions","portion"]);function Nu(t=85){let e="cooking:scale-servings";return {name:e,priority:t,shape:[{types:["IDENT"],values:["scale"]},{types:["NUMBER","BIGINT"]}],match(o,r){let n=o[r];if(n?.type!=="IDENT"||(n.value??"").toLowerCase()!=="scale")return null;let i=o[r+1];if(i?.type!=="NUMBER"&&i?.type!=="BIGINT")return null;let a=r+2,s=o[a];return s?.type==="IDENT"&&wd.has((s.value??"").toLowerCase())&&(a+=1),o[a]?.type!=="TO"?null:{consumed:1,replacement:[new chunk6EYKVQT3_cjs.a("SCALE_SERVINGS",kd,"scale",n.text??"scale",n.offset,0,n.line,n.col)],ruleName:e}}}}var Co=class{constructor(){this.category="Cooking";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall("gasMarkToCelsius",1);}};var Md=new Set(["servings","serving","serves","people","portions","portion"]),Io=class{constructor(){this.category="Cooking";}parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r);let n=e.peek(),i=n?.type==="STAR"?1:0,a=i===1?e.peekAt?.(1)??null:n;a&&Md.has((a.value??"").toLowerCase())&&(i===1&&e.consume(),e.consume()),e.consume("TO"),e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall("recipeScalingFactor",2);}};var ze={GAS_MARK_EXPECTED_TEMPERATURE:"GAS_MARK_EXPECTED_TEMPERATURE",GAS_MARK_OFF_THE_DIAL:"GAS_MARK_OFF_THE_DIAL",GAS_MARK_UNKNOWN:"GAS_MARK_UNKNOWN",SERVINGS_NOT_POSITIVE:"SERVINGS_NOT_POSITIVE"};function Bd(t){if(t.type!==6||t.unit===void 0)return chunkGJZIJK2Q_cjs.P(ze.GAS_MARK_EXPECTED_TEMPERATURE,'"in gas mark" expects an oven temperature, as in "180C in gas mark"');if(!chunkZKFCKAIX_cjs.d(t.unit,"C"))return chunkGJZIJK2Q_cjs.P(ze.GAS_MARK_EXPECTED_TEMPERATURE,`${t.unit} is not a temperature, so it names no gas mark`);let e=t.unit==="C"?t.toNumber():chunkZKFCKAIX_cjs.e(t.toNumber(),t.unit,"C"),o=Eu(e);if(o===null){let{coldest:r,hottest:n}=xi();return chunkGJZIJK2Q_cjs.P(ze.GAS_MARK_OFF_THE_DIAL,`${Math.round(e)}C is not a gas setting: the dial runs from gas ${r.written} (${r.celsius}C) to gas ${n.written} (${n.celsius}C)`)}return chunkGJZIJK2Q_cjs.t(`gas ${o.written}`)}function Ud(t){let e=t[0].toNumber(),o=du(e);if(o===null){let{coldest:r,hottest:n}=xi();return chunkGJZIJK2Q_cjs.P(ze.GAS_MARK_UNKNOWN,`there is no gas mark ${e}: the dial runs from ${r.written} to ${n.written}`)}return chunkGJZIJK2Q_cjs.u(o,"C")}function Dd(t){let e=t[0].toNumber(),o=t[1].toNumber();return !(e>0)||!(o>0)?chunkGJZIJK2Q_cjs.P(ze.SERVINGS_NOT_POSITIVE,`a recipe serves a positive number of people, so ${e} to ${o} names no scaling`):chunkGJZIJK2Q_cjs.n(o/e)}var Ri={name:"solve-cooking",phrases:{"gas mark":"CONVERTER_NAME"},normalizerRules:[Tu(),Nu()],prefixParselets:{GAS_MARK:new Co,SCALE_SERVINGS:new Io},pluginFunctions:{gasMarkToCelsius:Ud,recipeScalingFactor:Dd},asConverters:{"gas mark":Bd},tokenCategories:{GAS_MARK:"keyword",SCALE_SERVINGS:"keyword"}};var bd=chunkYBQOQTVL_cjs.c("UNIT");function yu(t=82){let e="fuel:l-per-100km";return {name:e,priority:t,shape:[{types:["UNIT","IDENT"],values:["l"]},{types:["SLASH"]}],match(o,r){let n=o[r],i=o[r+1],a=o[r+2],s=o[r+3];return !n||n.type!=="UNIT"&&n.type!=="IDENT"||(n.value??"").toLowerCase()!=="l"||i?.type!=="SLASH"||a?.type!=="NUMBER"||a.value!=="100"||s?.type!=="UNIT"||(s.value??"").toLowerCase()!=="km"?null:{consumed:4,replacement:[new chunk6EYKVQT3_cjs.a("UNIT",bd,"l100km","l/100km",n.offset,0,n.line,n.col)],ruleName:e}}}}var Oi={name:"solve-fuel",normalizerRules:[yu()]};var Vd=chunkYBQOQTVL_cjs.c("UNIT");function gu(t=82){let e="derived:acceleration";return {name:e,priority:t,shape:[{types:["UNIT"],values:["m"]},{types:["SLASH"]}],match(o,r){let n=o[r],i=o[r+1],a=o[r+2],s=o[r+3],l=o[r+4];return !n||n.type!=="UNIT"||(n.value??"")!=="m"||i?.type!=="SLASH"||a?.type!=="UNIT"||(a.value??"")!=="s"||s?.type!=="CARET"||l?.type!=="NUMBER"||l.value!=="2"?null:{consumed:5,replacement:[new chunk6EYKVQT3_cjs.a("UNIT",Vd,"mps2","m/s^2",n.offset,0,n.line,n.col)],ruleName:e}}}}function b(t){return e=>e.type!==6||!e.unit?chunkGJZIJK2Q_cjs.P("AS_UNIT_EXPECTED_QUANTITY",`"as ${t}" expects a quantity with a unit`):e.unit===t?e:chunkZKFCKAIX_cjs.d(e.unit,t)?chunkGJZIJK2Q_cjs.u(chunkZKFCKAIX_cjs.e(e.toNumber(),e.unit,t),t):chunkGJZIJK2Q_cjs.P("AS_UNIT_INCOMPATIBLE",`${e.unit} cannot be expressed as ${t}: they do not measure the same thing`)}var Ci={name:"solve-derived-units",normalizerRules:[gu()],asConverters:{n:b("N"),kn:b("kN"),j:b("J"),kj:b("kJ"),mj:b("MJ"),wh:b("Wh"),kwh:b("kWh"),w:b("W"),kw:b("kW"),mw:b("MW"),pa:b("Pa"),kpa:b("kPa"),mpa:b("MPa"),v:b("V"),mv:b("mV"),kv:b("kV")}};function Ii(t){return [...t].length}function Pu(t){return t.trim()}function _u(t){return [...t].reverse().join("")}function Au(t,e){return t.includes(e)}function xu(t,e){return t.startsWith(e)}function Ru(t,e){return t.endsWith(e)}function Ou(t,e,o){return e===""?t:t.split(e).join(o)}function Cu(t,e){let o=Math.trunc(e);return o<=0?"":t.repeat(o)}function ho(t){return t.toUpperCase()}function So(t){return t.toLowerCase()}function Lo(t){return t.replace(/\S+/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())}function vo(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Iu(t){let e=t.trim();return e===""?0:e.split(/\s+/).length}function hu(t){return t===""?0:t.split(/\r\n|\r|\n/).length}function ue(t){return t?.type===3?t.value:null}function xt(t){return chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED",`${t} expects text (a "quoted string")`)}function ko(t,e){return o=>{let r=ue(o[0]);return r===null?xt(t):chunkGJZIJK2Q_cjs.n(e(r))}}function Ke(t,e){return o=>{let r=ue(o[0]);return r===null?xt(t):chunkGJZIJK2Q_cjs.t(e(r))}}function Fd(t,e){if(e==="")return 0;let o=0,r=t.indexOf(e);for(;r!==-1;)o++,r=t.indexOf(e+"",r+e.length);return o}function hi(t,e){return o=>{let r=ue(o[0]),n=ue(o[1]);return r===null||n===null?xt(t):chunkGJZIJK2Q_cjs.L(e(r,n))}}var Su={textLength:ko("length",Ii),textWordCount:ko("words in",Iu),textCharCount:ko("characters in",Ii),textLineCount:ko("lines in",hu),textTrim:Ke("trim",Pu),textReverse:Ke("reverse",_u),textUpper:Ke('"as upper"',ho),textLower:Ke('"as lower"',So),textTitle:Ke('"as title"',Lo),textSlug:Ke('"as slug"',vo),textContains:hi("contains",Au),textStartsWith:hi("starts with",xu),textEndsWith:hi("ends with",Ru),textReplace:t=>{let e=ue(t[0]),o=ue(t[1]),r=ue(t[2]);if(e===null||o===null||r===null)return xt("replace");let n=Fd(e,o)*(r.length-o.length);return chunkGJZIJK2Q_cjs.d(Math.max(0,e.length+n),"characters"),chunkGJZIJK2Q_cjs.t(Ou(e,o,r))},textRepeat:t=>{let e=ue(t[0]);if(e===null)return xt("repeat");let o=t[1];if(o?.type!==0)return chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED","repeat expects a count (a number)");let r=Math.max(0,Math.trunc(o.value));return chunkGJZIJK2Q_cjs.d(e.length*r,"characters"),chunkGJZIJK2Q_cjs.t(Cu(e,o.value))}};function Pe(t,e){return {category:"Text",parse(o,r,n){o.parseExpression(e,n),n.emitPluginCall(t,1);}}}function wo(t){return {category:"Text",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(e,o,r,n){e.parseExpression(chunkZDJTDFTR_cjs.a.Conditional,n),n.emitPluginCall(t,2);}}}var Lu={category:"Text",bindingPower:chunkZDJTDFTR_cjs.a.Conditional,parse(t,e,o,r){t.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r);let n=t.peek();n?.type==="STAR"&&(n.value??"").toLowerCase()==="times"&&t.consume(),r.emitPluginCall("textRepeat",2);}};var Mo={length:"textLength",upper:"textUpper",uppercase:"textUpper",lower:"textLower",lowercase:"textLower",title:"textTitle",titlecase:"textTitle",slug:"textSlug",slugify:"textSlug",replace:"textReplace",repeat:"textRepeat",words:"textWordCount",wordcount:"textWordCount",characters:"textCharCount",charcount:"textCharCount",lines:"textLineCount",linecount:"textLineCount"};var Bo=class{constructor(){this.category="Text";}parse(e,o,r){let n=Mo[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown text function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};function Uo(t,e){return o=>o.type!==3?chunkGJZIJK2Q_cjs.P("TEXT_EXPECTED",`"as ${t}" expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(o.value))}var Si={name:"solve-text",phrases:{"length of":"LENGTH_OF","words in":"WORDS_IN","characters in":"CHARACTERS_IN","lines in":"LINES_IN","starts with":"STARTS_WITH","ends with":"ENDS_WITH"},lexerVocabulary:{keywords:{trim:"TRIM",reverse:"REVERSE",contains:"CONTAINS",repeated:"REPEATED"}},prefixParselets:{LENGTH_OF:Pe("textLength",chunkZDJTDFTR_cjs.a.Lowest),WORDS_IN:Pe("textWordCount",chunkZDJTDFTR_cjs.a.Lowest),CHARACTERS_IN:Pe("textCharCount",chunkZDJTDFTR_cjs.a.Lowest),LINES_IN:Pe("textLineCount",chunkZDJTDFTR_cjs.a.Lowest),TRIM:Pe("textTrim",chunkZDJTDFTR_cjs.a.Prefix),REVERSE:Pe("textReverse",chunkZDJTDFTR_cjs.a.Prefix),TEXT_CALL:new Bo},infixParselets:{CONTAINS:wo("textContains"),STARTS_WITH:wo("textStartsWith"),ENDS_WITH:wo("textEndsWith"),REPEATED:Lu},asConverters:{upper:Uo("upper",ho),lower:Uo("lower",So),title:Uo("title",Lo),slug:Uo("slug",vo)},callFusions:Object.fromEntries(Object.keys(Mo).map(t=>[t,"TEXT_CALL"])),pluginFunctions:Su,tokenCategories:{LENGTH_OF:"function",WORDS_IN:"function",CHARACTERS_IN:"function",LINES_IN:"function",TRIM:"function",REVERSE:"function",TEXT_CALL:"function",CONTAINS:"operator",STARTS_WITH:"operator",ENDS_WITH:"operator",REPEATED:"operator"}};function Rt(t){return new TextEncoder().encode(t)}function Li(t){let e="";for(let o of t)e+=o.toString(16).padStart(2,"0");return e}var Hd=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let o=e;for(let r=0;r<8;r++)o=o&1?3988292384^o>>>1:o>>>1;t[e]=o>>>0;}return t})();function vu(t){let e=Rt(t),o=4294967295;for(let r of e)o=Hd[(o^r)&255]^o>>>8;return o=(o^4294967295)>>>0,o.toString(16).padStart(8,"0")}function Gd(t){let e=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],o=new Int32Array(64);for(let N=0;N<64;N++)o[N]=Math.floor(Math.abs(Math.sin(N+1))*4294967296);let r=t.length*8,n=new Uint8Array(((t.length+8>>6)+1)*64);n.set(t),n[t.length]=128;let i=new DataView(n.buffer);i.setUint32(n.length-8,r>>>0,true),i.setUint32(n.length-4,Math.floor(r/4294967296)>>>0,true);let a=1732584193,s=4023233417,l=2562383102,u=271733878,c=(N,E)=>N<<E|N>>>32-E;for(let N=0;N<n.length;N+=64){let E=new Int32Array(16);for(let A=0;A<16;A++)E[A]=i.getUint32(N+A*4,true);let P=a,R=s,O=l,g=u;for(let A=0;A<64;A++){let S,v;A<16?(S=R&O|~R&g,v=A):A<32?(S=g&R|~g&O,v=(5*A+1)%16):A<48?(S=R^O^g,v=(3*A+5)%16):(S=O^(R|~g),v=7*A%16),S=S+P+o[A]+E[v]|0,P=g,g=O,O=R,R=R+c(S,e[A])|0;}a=a+P|0,s=s+R|0,l=l+O|0,u=u+g|0;}let f=new Uint8Array(16),T=new DataView(f.buffer);return T.setUint32(0,a>>>0,true),T.setUint32(4,s>>>0,true),T.setUint32(8,l>>>0,true),T.setUint32(12,u>>>0,true),f}function ku(t){return Li(Gd(Rt(t)))}function zd(t){let e=t.length*8,o=new Uint8Array(((t.length+8>>6)+1)*64);o.set(t),o[t.length]=128;let r=new DataView(o.buffer);r.setUint32(o.length-8,Math.floor(e/4294967296)>>>0),r.setUint32(o.length-4,e>>>0);let n=1732584193,i=4023233417,a=2562383102,s=271733878,l=3285377520,u=(N,E)=>N<<E|N>>>32-E,c=new Int32Array(80);for(let N=0;N<o.length;N+=64){for(let A=0;A<16;A++)c[A]=r.getUint32(N+A*4);for(let A=16;A<80;A++)c[A]=u(c[A-3]^c[A-8]^c[A-14]^c[A-16],1);let E=n,P=i,R=a,O=s,g=l;for(let A=0;A<80;A++){let S,v;A<20?(S=P&R|~P&O,v=1518500249):A<40?(S=P^R^O,v=1859775393):A<60?(S=P&R|P&O|R&O,v=2400959708):(S=P^R^O,v=3395469782);let q=u(E,5)+S+g+v+c[A]|0;g=O,O=R,R=u(P,30),P=E,E=q;}n=n+E|0,i=i+P|0,a=a+R|0,s=s+O|0,l=l+g|0;}let f=new Uint8Array(20),T=new DataView(f.buffer);return [n,i,a,s,l].forEach((N,E)=>T.setUint32(E*4,N>>>0)),f}function wu(t){return Li(zd(Rt(t)))}var Kd=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function $d(t){let e=t.length*8,o=new Uint8Array(((t.length+8>>6)+1)*64);o.set(t),o[t.length]=128;let r=new DataView(o.buffer);r.setUint32(o.length-8,Math.floor(e/4294967296)>>>0),r.setUint32(o.length-4,e>>>0);let n=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),i=(u,c)=>u>>>c|u<<32-c,a=new Uint32Array(64);for(let u=0;u<o.length;u+=64){for(let g=0;g<16;g++)a[g]=r.getUint32(u+g*4);for(let g=16;g<64;g++){let A=i(a[g-15],7)^i(a[g-15],18)^a[g-15]>>>3,S=i(a[g-2],17)^i(a[g-2],19)^a[g-2]>>>10;a[g]=a[g-16]+A+a[g-7]+S|0;}let[c,f,T,N,E,P,R,O]=n;for(let g=0;g<64;g++){let A=i(E,6)^i(E,11)^i(E,25),S=E&P^~E&R,v=O+A+S+Kd[g]+a[g]|0,q=i(c,2)^i(c,13)^i(c,22),Ye=c&f^c&T^f&T,pe=q+Ye|0;O=R,R=P,P=E,E=N+v|0,N=T,T=f,f=c,c=v+pe|0;}n[0]=n[0]+c|0,n[1]=n[1]+f|0,n[2]=n[2]+T|0,n[3]=n[3]+N|0,n[4]=n[4]+E|0,n[5]=n[5]+P|0,n[6]=n[6]+R|0,n[7]=n[7]+O|0;}let s=new Uint8Array(32),l=new DataView(s.buffer);for(let u=0;u<8;u++)l.setUint32(u*4,n[u]>>>0);return s}function Mu(t){return Li($d(Rt(t)))}var F=(1n<<64n)-1n,Wd=[0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n];function Bu(t){let e=Rt(t),o=((e.length+16>>7)+1)*128,r=new Uint8Array(o);r.set(e),r[e.length]=128;let n=BigInt(e.length)*8n,i=new DataView(r.buffer);i.setUint32(r.length-4,Number(n&0xffffffffn)),i.setUint32(r.length-8,Number(n>>32n&0xffffffffn));let a=[0x6a09e667f3bcc908n,0xbb67ae8584caa73bn,0x3c6ef372fe94f82bn,0xa54ff53a5f1d36f1n,0x510e527fade682d1n,0x9b05688c2b3e6c1fn,0x1f83d9abfb41bd6bn,0x5be0cd19137e2179n],s=(u,c)=>(u>>c|u<<64n-c)&F,l=new Array(80);for(let u=0;u<r.length;u+=128){for(let g=0;g<16;g++){let A=BigInt(i.getUint32(u+g*8)),S=BigInt(i.getUint32(u+g*8+4));l[g]=A<<32n|S;}for(let g=16;g<80;g++){let A=s(l[g-15],1n)^s(l[g-15],8n)^l[g-15]>>7n,S=s(l[g-2],19n)^s(l[g-2],61n)^l[g-2]>>6n;l[g]=l[g-16]+A+l[g-7]+S&F;}let[c,f,T,N,E,P,R,O]=a;for(let g=0;g<80;g++){let A=s(E,14n)^s(E,18n)^s(E,41n),S=E&P^~E&F&R,v=O+A+S+Wd[g]+l[g]&F,q=s(c,28n)^s(c,34n)^s(c,39n),Ye=c&f^c&T^f&T,pe=q+Ye&F;O=R,R=P,P=E,E=N+v&F,N=T,T=f,f=c,c=v+pe&F;}a[0]=a[0]+c&F,a[1]=a[1]+f&F,a[2]=a[2]+T&F,a[3]=a[3]+N&F,a[4]=a[4]+E&F,a[5]=a[5]+P&F,a[6]=a[6]+R&F,a[7]=a[7]+O&F;}return a.map(u=>u.toString(16).padStart(16,"0")).join("")}var Do={md5:"hashMd5",sha1:"hashSha1",sha256:"hashSha256",sha512:"hashSha512",crc32:"hashCrc32"};function Ot(t,e){return o=>{let r=o[0];return r?.type!==3?chunkGJZIJK2Q_cjs.P("HASH_EXPECTED_TEXT",`${t}(...) expects text (a "quoted string")`):chunkGJZIJK2Q_cjs.t(e(r.value))}}var Uu={hashMd5:Ot("md5",ku),hashSha1:Ot("sha1",wu),hashSha256:Ot("sha256",Mu),hashSha512:Ot("sha512",Bu),hashCrc32:Ot("crc32",vu)};var bo=class{constructor(){this.category="Hash";}parse(e,o,r){let n=Do[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown hash function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var vi={name:"solve-hash",prefixParselets:{HASH_CALL:new bo},callFusions:Object.fromEntries(Object.keys(Do).map(t=>[t,"HASH_CALL"])),pluginFunctions:Uu,tokenCategories:{HASH_CALL:"function"}};var Du="0123456789abcdef";function bu(){return Du[Math.floor(Math.random()*16)]}function Yd(){let t="";for(let e=0;e<36;e++)e===8||e===13||e===18||e===23?t+="-":e===14?t+="4":e===19?t+=Du[Math.floor(Math.random()*16)&3|8]:t+=bu();return t}function jd(t){let e="";for(let o=0;o<t;o++)e+=bu();return e}var Vu={randomUuid:()=>chunkGJZIJK2Q_cjs.t(Yd()),randomCoin:()=>chunkGJZIJK2Q_cjs.t(Math.random()<.5?"heads":"tails"),randomHex:t=>{let e=t[0];if(e?.type!==0)return chunkGJZIJK2Q_cjs.P("RANDOM_EXPECTED_COUNT","random hex expects a number of digits");let o=Math.trunc(e.value);return o<0?chunkGJZIJK2Q_cjs.P("RANDOM_EXPECTED_COUNT","random hex needs a count of 0 or more"):chunkGJZIJK2Q_cjs.t(jd(o))},randomPick:t=>t.length===0?chunkGJZIJK2Q_cjs.P("RANDOM_PICK_EMPTY","pick needs at least one option"):t[Math.floor(Math.random()*t.length)],randomShuffle:t=>{let e=t[0];if(e?.type!==7)return chunkGJZIJK2Q_cjs.P("RANDOM_SHUFFLE_EXPECTED_LIST","shuffle expects a list, e.g. shuffle [1, 2, 3]");let o=e.value;if(o.rows!==1&&o.cols!==1)return chunkGJZIJK2Q_cjs.P("RANDOM_SHUFFLE_EXPECTED_LIST","shuffle expects a single row or column, not a full matrix");let r=o.data.slice();for(let n=r.length-1;n>0;n--){let i=Math.floor(Math.random()*(n+1));[r[n],r[i]]=[r[i],r[n]];}return chunkGJZIJK2Q_cjs.C(o.rows,o.cols,r)}};function ki(t){return {category:"Random",parse(e,o,r){r.emitPluginCall(t,0);}}}function wi(t){return {category:"Random",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Prefix,r),r.emitPluginCall(t,1);}}}var Fu={category:"Random",parse(t,e,o){t.consume("LPAREN");let r=0;if(t.peek()?.type!=="RPAREN")for(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.match("COMMA");)t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.consume("RPAREN"),o.emitPluginCall("randomPick",r);}};var Mi={name:"solve-random",phrases:{"random hex":"RANDOM_HEX"},lexerVocabulary:{keywords:{uuid:"UUID",coin:"COIN",shuffle:"SHUFFLE"}},prefixParselets:{UUID:ki("randomUuid"),COIN:ki("randomCoin"),RANDOM_HEX:wi("randomHex"),SHUFFLE:wi("randomShuffle"),PICK_CALL:Fu},callFusions:{pick:"PICK_CALL"},pluginFunctions:Vu,tokenCategories:{UUID:"function",COIN:"function",RANDOM_HEX:"function",SHUFFLE:"function",PICK_CALL:"function"}};function ce(t){return t.reduce((e,o)=>e+o,0)/t.length}function Xd(t){let e=ce(t);return t.reduce((o,r)=>o+(r-e)*(r-e),0)/t.length}function Qd(t){return Math.sqrt(Xd(t))}function Bi(t,e){let o=ce(t),r=ce(e),n=0,i=0,a=0;for(let l=0;l<t.length;l++){let u=t[l]-o,c=e[l]-r;n+=u*c,i+=u*u,a+=c*c;}let s=Math.sqrt(i*a);return s===0?NaN:n/s}function Ui(t,e){let o=ce(t),r=ce(e),n=0,i=0;for(let a=0;a<t.length;a++){let s=t[a]-o;n+=s*(e[a]-r),i+=s*s;}return i===0?NaN:n/i}function Hu(t,e){return ce(e)-Ui(t,e)*ce(t)}function Gu(t,e){let o=Bi(t,e);return o*o}function zu(t,e){let o=[...t].sort((a,s)=>a-s);if(o.length===1)return o[0];let r=e/100*(o.length-1),n=Math.floor(r),i=Math.ceil(r);return n===i?o[n]:o[n]+(r-n)*(o[i]-o[n])}function Ku(t,e){let o=Qd(e);return o===0?NaN:(t-ce(e))/o}function qd(t){let e=t<0?-1:1,o=1/(1+.3275911*Math.abs(t)),r=1-((((1.061405429*o-1.453152027)*o+1.421413741)*o-.284496736)*o+.254829592)*o*Math.exp(-t*t);return e*r}function $u(t){return .5*(1+qd(t/Math.SQRT2))}function Wu(t){return Math.exp(-0.5*t*t)/Math.sqrt(2*Math.PI)}function Fo(t){if(!t)return null;if(t.type===7){let e=t.value;return e.hasSymbolic||e.rows!==1&&e.cols!==1?null:e.data.slice()}if(t.type===8){let e=t.value,o=[];for(let r=Math.ceil(e.min);r<=e.max;r++)o.push(r);return o}return t.type===0?[t.value]:null}function Vo(t,e){return o=>{let r=Fo(o[0]),n=Fo(o[1]);return r===null||n===null?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LISTS",`${t} expects two lists, e.g. ${t} of [1, 2, 3] and [2, 4, 6]`):r.length!==n.length?chunkGJZIJK2Q_cjs.P("STAT_LENGTH_MISMATCH",`${t}: the two lists must be the same length (got ${r.length} and ${n.length})`):r.length<2?chunkGJZIJK2Q_cjs.P("STAT_TOO_FEW",`${t} needs at least two paired points`):chunkGJZIJK2Q_cjs.n(e(r,n))}}var Yu={statCorrelation:Vo("correlation",Bi),statSlope:Vo("slope",Ui),statIntercept:Vo("intercept",Hu),statRSquared:Vo("r squared",Gu),statPercentile:t=>{let e=Fo(t[0]),o=t[1];if(e===null)return chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LIST","percentile expects a list, e.g. percentile([1, 2, 3], 90)");if(e.length===0)return chunkGJZIJK2Q_cjs.P("STAT_EMPTY","percentile needs at least one value");if(o?.type!==0)return chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_PERCENT","percentile needs a percentage, e.g. percentile([...], 90)");let r=o.value;return r<0||r>100?chunkGJZIJK2Q_cjs.P("STAT_PERCENT_RANGE","a percentile is between 0 and 100"):chunkGJZIJK2Q_cjs.n(zu(e,r))},statZScore:t=>{let e=t[0],o=Fo(t[1]);return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","zscore expects a value first, e.g. zscore(5, [1, 2, 3])"):o===null||o.length<2?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_LIST","zscore expects a list of at least two values"):chunkGJZIJK2Q_cjs.n(Ku(e.value,o))},statNormalCdf:t=>{let e=t[0];return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","normalcdf expects a number"):chunkGJZIJK2Q_cjs.n($u(e.value))},statNormalPdf:t=>{let e=t[0];return e?.type!==0?chunkGJZIJK2Q_cjs.P("STAT_EXPECTED_VALUE","normalpdf expects a number"):chunkGJZIJK2Q_cjs.n(Wu(e.value))}};function Ho(t){return {category:"Statistics",parse(e,o,r){e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),e.consume("AND_CONJ"),e.parseExpression(chunkZDJTDFTR_cjs.a.Conjunction,r),r.emitPluginCall(t,2);}}}var Go={correlation:"statCorrelation",slope:"statSlope",intercept:"statIntercept",rsquared:"statRSquared",percentile:"statPercentile",zscore:"statZScore",normalcdf:"statNormalCdf",normalpdf:"statNormalPdf"};var zo=class{constructor(){this.category="Statistics";}parse(e,o,r){let n=Go[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown statistics function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};var Di={name:"solve-statistics",phrases:{"correlation of":"CORRELATION_OF","slope of":"SLOPE_OF","intercept of":"INTERCEPT_OF"},prefixParselets:{CORRELATION_OF:Ho("statCorrelation"),SLOPE_OF:Ho("statSlope"),INTERCEPT_OF:Ho("statIntercept"),STAT_CALL:new zo},callFusions:Object.fromEntries(Object.keys(Go).map(t=>[t,"STAT_CALL"])),pluginFunctions:Yu,tokenCategories:{CORRELATION_OF:"function",SLOPE_OF:"function",INTERCEPT_OF:"function",STAT_CALL:"function"}};var Zd=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],ju={I:1,V:5,X:10,L:50,C:100,D:500,M:1e3};function bi(t){if(!Number.isInteger(t)||t<1||t>3999)return null;let e="",o=t;for(let[r,n]of Zd)for(;o>=r;)e+=n,o-=r;return e}function Xu(t){let e=t.trim().toUpperCase();if(e===""||!/^[MDCLXVI]+$/.test(e))return null;let o=0;for(let r=0;r<e.length;r++){let n=ju[e[r]],i=r+1<e.length?ju[e[r+1]]:0;o+=n<i?-n:n;}return bi(o)===e?o:null}function Qu(t){if(!Number.isInteger(t))return null;let e=Math.abs(t),o=e%100,r=e%10,n="th";return (o<11||o>13)&&(r===1?n="st":r===2?n="nd":r===3&&(n="rd")),`${t}${n}`}var Ko=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],Jd=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],eE=["","thousand","million","billion","trillion","quadrillion"];function tE(t){if(t<20)return Ko[t];let e=Math.floor(t/10),o=t%10;return Jd[e]+(o?`-${Ko[o]}`:"")}function rE(t){let e=Math.floor(t/100),o=t%100,r=[];return e&&r.push(`${Ko[e]} hundred`),o&&(e&&r.push("and"),r.push(tE(o))),r.join(" ")}function oE(t){if(t===0)return "zero";let e=[],o=t;for(;o>0;)e.push(o%1e3),o=Math.floor(o/1e3);let r=[];for(let i=e.length-1;i>=0;i--){if(e[i]===0)continue;let a=rE(e[i]);i>0&&(a+=` ${eE[i]}`),r.push({scale:i,group:e[i],words:a});}let n="";for(let i=0;i<r.length;i++){if(i>0){let a=i===r.length-1;n+=a&&r[i].scale===0&&r[i].group<100?" and ":" ";}n+=r[i].words;}return n}function qu(t){if(!Number.isFinite(t))return null;let e=Math.abs(t).toString();if(e.includes("e")||e.includes("E"))return null;let[o,r]=e.split("."),n=oE(parseInt(o,10));return r&&(n+=" point "+[...r].map(i=>Ko[Number(i)]).join(" ")),(t<0?"minus ":"")+n}var $o=class{constructor(){this.category="Numerals";this.bindingPower=chunkZDJTDFTR_cjs.a.Conditional;}parse(e,o,r,n){n.emitPluginCall("romanFromString",1);}};function Vi(t,e){return o=>{if(o.type!==0)return chunkGJZIJK2Q_cjs.P("NUMERAL_EXPECTED_NUMBER",`"as ${t}" expects a number`);let r=e(o.value);return r===null?chunkGJZIJK2Q_cjs.P("NUMERAL_OUT_OF_RANGE",`${o.value} cannot be written as ${t}`):chunkGJZIJK2Q_cjs.t(r)}}var Fi={name:"solve-numerals",phrases:{"from roman":"FROM_ROMAN"},asConverters:{roman:Vi("roman",bi),ordinal:Vi("ordinal",Qu),words:Vi("words",qu)},infixParselets:{FROM_ROMAN:new $o},pluginFunctions:{romanFromString:t=>{let e=t[0];if(e?.type!==3)return chunkGJZIJK2Q_cjs.P("NUMERAL_EXPECTED_TEXT",'"from roman" expects text, e.g. "MMXXIV" from roman');let o=Xu(e.value);return o===null?chunkGJZIJK2Q_cjs.P("NUMERAL_INVALID_ROMAN",`"${e.value}" is not a valid Roman numeral`):chunkGJZIJK2Q_cjs.n(o)}},tokenCategories:{FROM_ROMAN:"operator"}};function nE(t,e){for(t=Math.abs(t),e=Math.abs(e);e;)[t,e]=[e,t%e];return t}function Zu(t){if(t.length<2||t.some(o=>!Number.isInteger(o)||o<=0))return null;let e=t.reduce((o,r)=>nE(o,r),0)||1;return t.map(o=>o/e).join(":")}var Ju={category:"Ratio",parse(t,e,o){t.consume("LPAREN");let r=0;if(t.peek()?.type!=="RPAREN")for(t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.match("COMMA");)t.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,o),r++;t.consume("RPAREN"),o.emitPluginCall("ratioReduce",r);}};var Hi={name:"solve-ratio",prefixParselets:{RATIO_CALL:Ju},callFusions:{ratio:"RATIO_CALL"},pluginFunctions:{ratioReduce:t=>{let e=[];for(let r of t){if(r.type!==0)return chunkGJZIJK2Q_cjs.P("RATIO_EXPECTED_NUMBERS","ratio expects whole numbers, e.g. ratio(16, 9)");e.push(r.value);}let o=Zu(e);return o===null?chunkGJZIJK2Q_cjs.P("RATIO_INVALID","ratio needs at least two whole positive numbers"):chunkGJZIJK2Q_cjs.t(o)}},tokenCategories:{RATIO_CALL:"function"}};var _e=Math.PI;function G(t,e){let o=[];for(let r of e){if(!(r in t))return null;o.push(t[r]);}return o}var Gi=["circle","square","rectangle","triangle","sphere","cube","cylinder","cone"],ec=["radius","side","width","height","base","length"];function tc(t,e,o){let r=i=>({error:`the ${t} of a ${e} needs its ${i}`}),n={error:`the ${t} of a ${e} is not one of the shapes this supports`};switch(`${t}:${e}`){case "area:circle":{let i=G(o,["radius"]);return i?{value:_e*i[0]**2}:r("radius")}case "perimeter:circle":case "circumference:circle":{let i=G(o,["radius"]);return i?{value:2*_e*i[0]}:r("radius")}case "area:square":{let i=G(o,["side"]);return i?{value:i[0]**2}:r("side")}case "perimeter:square":{let i=G(o,["side"]);return i?{value:4*i[0]}:r("side")}case "area:rectangle":{let i=G(o,["width","height"]);return i?{value:i[0]*i[1]}:r("width and height")}case "perimeter:rectangle":{let i=G(o,["width","height"]);return i?{value:2*(i[0]+i[1])}:r("width and height")}case "area:triangle":{let i=G(o,["base","height"]);return i?{value:.5*i[0]*i[1]}:r("base and height")}case "volume:sphere":{let i=G(o,["radius"]);return i?{value:4/3*_e*i[0]**3}:r("radius")}case "surface:sphere":{let i=G(o,["radius"]);return i?{value:4*_e*i[0]**2}:r("radius")}case "volume:cube":{let i=G(o,["side"]);return i?{value:i[0]**3}:r("side")}case "surface:cube":{let i=G(o,["side"]);return i?{value:6*i[0]**2}:r("side")}case "volume:cylinder":{let i=G(o,["radius","height"]);return i?{value:_e*i[0]**2*i[1]}:r("radius and height")}case "surface:cylinder":{let i=G(o,["radius","height"]);return i?{value:2*_e*i[0]*(i[0]+i[1])}:r("radius and height")}case "volume:cone":{let i=G(o,["radius","height"]);return i?{value:1/3*_e*i[0]**2*i[1]}:r("radius and height")}default:return n}}var iE=new Set(Gi),aE=new Set(ec);function $e(t){return {category:"Geometry",parse(e,o,r){let n=e.peek(),i=(n?.value??"").toLowerCase();if(!n||n.type!=="IDENT"||!iE.has(i))throw chunkGXO7TSXQ_cjs.c.parsing("GEOMETRY_EXPECTED_SHAPE",`Expected a shape (${Gi.join(", ")}) after "${t} of" but got ${n?`"${n.value}"`:"end of input"}`);e.consume(),r.emitOpcode(13),r.emitString(t),r.emitOpcode(13),r.emitString(i);let a=2;for(;;){let s=e.peek(),l=(s?.value??"").toLowerCase();if(!s||s.type!=="IDENT"||!aE.has(l))break;e.consume(),r.emitOpcode(13),r.emitString(l),a++,e.parseExpression(chunkZDJTDFTR_cjs.a.Call,r),a++,e.peek()?.type==="COMMA"&&e.consume();}r.emitPluginCall("geometryCompute",a);}}}var zi={name:"solve-geometry",phrases:{"area of":"AREA_OF","perimeter of":"PERIMETER_OF","circumference of":"CIRCUMFERENCE_OF","volume of":"VOLUME_OF","surface area of":"SURFACE_AREA_OF"},prefixParselets:{AREA_OF:$e("area"),PERIMETER_OF:$e("perimeter"),CIRCUMFERENCE_OF:$e("circumference"),VOLUME_OF:$e("volume"),SURFACE_AREA_OF:$e("surface")},pluginFunctions:{geometryCompute:t=>{let e=String(t[0]?.value??""),o=String(t[1]?.value??""),r={};for(let i=2;i+1<t.length;i+=2){let a=String(t[i]?.value??""),s=t[i+1];if(s?.type===13)return s;r[a]=s?.toNumber()??NaN;}let n=tc(e,o,r);return n.error!==void 0?chunkGJZIJK2Q_cjs.P("GEOMETRY_ERROR",n.error):chunkGJZIJK2Q_cjs.n(n.value)}},tokenCategories:{AREA_OF:"function",PERIMETER_OF:"function",CIRCUMFERENCE_OF:"function",VOLUME_OF:"function",SURFACE_AREA_OF:"function"}};var sE={"speed of light":{value:299792458,unit:"m/s"},gravity:{value:9.80665,unit:"mps2"},"electron mass":{value:91093837015e-41,unit:"kg"},"proton mass":{value:167262192369e-38,unit:"kg"},avogadro:{value:602214076e15},planck:{value:662607015e-42},boltzmann:{value:1380649e-29},"elementary charge":{value:1602176634e-28},"gas constant":{value:8.314462618},tau:{value:6.283185307179586},"golden ratio":{value:1.618033988749895},phi:{value:1.618033988749895}};function rc(t){return sE[t.toLowerCase()]??null}function K(t){return {category:"Constants",parse(e,o,r){r.emitOpcode(13),r.emitString(t),r.emitPluginCall("constantValue",1);}}}var Ki={name:"solve-constants",phrases:{"speed of light":"SPEED_OF_LIGHT","electron mass":"ELECTRON_MASS","proton mass":"PROTON_MASS","elementary charge":"ELEMENTARY_CHARGE","gas constant":"GAS_CONSTANT","golden ratio":"GOLDEN_RATIO"},lexerVocabulary:{keywords:{gravity:"GRAVITY",avogadro:"AVOGADRO",planck:"PLANCK",boltzmann:"BOLTZMANN",tau:"TAU",phi:"PHI"}},prefixParselets:{SPEED_OF_LIGHT:K("speed of light"),ELECTRON_MASS:K("electron mass"),PROTON_MASS:K("proton mass"),ELEMENTARY_CHARGE:K("elementary charge"),GAS_CONSTANT:K("gas constant"),GOLDEN_RATIO:K("golden ratio"),GRAVITY:K("gravity"),AVOGADRO:K("avogadro"),PLANCK:K("planck"),BOLTZMANN:K("boltzmann"),TAU:K("tau"),PHI:K("phi")},pluginFunctions:{constantValue:t=>{let e=t[0]?.type===3?t[0].value:"",o=rc(e);return o===null?chunkGJZIJK2Q_cjs.P("UNKNOWN_CONSTANT",`"${e}" is not a known constant`):o.unit?chunkGJZIJK2Q_cjs.u(o.value,o.unit):chunkGJZIJK2Q_cjs.n(o.value)}},tokenCategories:{SPEED_OF_LIGHT:"keyword",ELECTRON_MASS:"keyword",PROTON_MASS:"keyword",ELEMENTARY_CHARGE:"keyword",GAS_CONSTANT:"keyword",GOLDEN_RATIO:"keyword",GRAVITY:"keyword",AVOGADRO:"keyword",PLANCK:"keyword",BOLTZMANN:"keyword",TAU:"keyword",PHI:"keyword"}};function oc(t,e){return t/(e*e)}function nc(t,e){return t*60/e}function ic(t,e){let o=e/t,r=Math.floor(o),n=Math.round((o-r)*60);return n===60&&(r+=1,n=0),`${r}:${n.toString().padStart(2,"0")}`}var Wo={bmi:"healthBmi",pace:"healthPace",speed:"healthSpeed"};var Yo=class{constructor(){this.category="Health";}parse(e,o,r){let n=Wo[o.value];if(n===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_FUNCTION",`Unknown health function: ${o.value}`,{functionName:o.value});e.consume("LPAREN");let i=0;if(e.peek()?.type!=="RPAREN")for(e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.match("COMMA");)e.parseExpression(chunkZDJTDFTR_cjs.a.Lowest,r),i++;e.consume("RPAREN"),r.emitPluginCall(n,i);}};function We(t){return t?.type===0?t.value:t?.type===6?t.toNumber():null}var $i={name:"solve-health",prefixParselets:{HEALTH_CALL:new Yo},callFusions:Object.fromEntries(Object.keys(Wo).map(t=>[t,"HEALTH_CALL"])),pluginFunctions:{healthBmi:t=>{let e=We(t[0]),o=We(t[1]);return e===null||o===null||o===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","bmi(weight in kg, height in m), e.g. bmi(70, 1.75)"):chunkGJZIJK2Q_cjs.n(oc(e,o))},healthPace:t=>{let e=We(t[0]),o=We(t[1]);return e===null||o===null||e===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","pace(distance in km, time in min), e.g. pace(10, 50)"):chunkGJZIJK2Q_cjs.t(`${ic(e,o)} /km`)},healthSpeed:t=>{let e=We(t[0]),o=We(t[1]);return e===null||o===null||o===0?chunkGJZIJK2Q_cjs.P("HEALTH_BAD_INPUT","speed(distance in km, time in min), e.g. speed(10, 50)"):chunkGJZIJK2Q_cjs.u(nc(e,o),"km/h")}},tokenCategories:{HEALTH_CALL:"function"}};var Mv=[mn,ln,cn,En,xn,Rn,On,vn,wn,Mn,Bn,Un,chunk7RC6RBS6_cjs.a,Dn,bn,Vn,Hn,Wn,ai,si,mi,Yn,qn,li,Zn,fi,Ei,_i,Ai,Ri,Oi,Ci,ti,Si,vi,Mi,Di,Fi,Hi,zi,Ki,$i];
2
+ exports.a=mn;exports.b=ln;exports.c=cn;exports.d=En;exports.e=xn;exports.f=Rn;exports.g=On;exports.h=vn;exports.i=kn;exports.j=wn;exports.k=Mn;exports.l=Bn;exports.m=Un;exports.n=Dn;exports.o=bn;exports.p=Vn;exports.q=Hn;exports.r=Wn;exports.s=Yn;exports.t=qm;exports.u=Jm;exports.v=tl;exports.w=qn;exports.x=Zn;exports.y=ti;exports.z=Mv;//# sourceMappingURL=chunk-DFMAZ6XM.cjs.map
3
+ //# sourceMappingURL=chunk-DFMAZ6XM.cjs.map