solve-engine 2.25.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 (240) hide show
  1. package/dist/CalendarBackend-MdS3Bb4P.d.cts +181 -0
  2. package/dist/CalendarBackend-MdS3Bb4P.d.ts +181 -0
  3. package/dist/{Configuration-DnzYPmoK.d.cts → Configuration-BxriK9Kw.d.cts} +63 -4
  4. package/dist/{Configuration-DnzYPmoK.d.ts → Configuration-BxriK9Kw.d.ts} +63 -4
  5. package/dist/DateCalendar-B85t6Vk6.d.ts +90 -0
  6. package/dist/DateCalendar-CUGI1fT4.d.cts +90 -0
  7. package/dist/{EngineError-fR1K1rvx.d.cts → EngineError-C-kBwYlN.d.cts} +31 -4
  8. package/dist/{EngineError-fR1K1rvx.d.ts → EngineError-C-kBwYlN.d.ts} +31 -4
  9. package/dist/{FormattingSettings-bRKjU7wI.d.ts → FormattingSettings-ByO-4wiM.d.cts} +14 -0
  10. package/dist/{FormattingSettings-bRKjU7wI.d.cts → FormattingSettings-CvCzAfsz.d.ts} +14 -0
  11. package/dist/{Lexer-aB95pjoX.d.cts → Lexer-DhGhoAa2.d.cts} +13 -3
  12. package/dist/{Lexer-Bmctxl0n.d.ts → Lexer-DqtnZMC5.d.ts} +13 -3
  13. package/dist/{PackageCompatibility-CUVg8tmt.d.cts → PackageCompatibility-CNiTtC6S.d.cts} +1 -1
  14. package/dist/{PackageCompatibility-BludTs7v.d.ts → PackageCompatibility-fj_f7uqC.d.ts} +1 -1
  15. package/dist/{PackageRegistry-Dvn4i2QK.d.cts → PackageRegistry-BHBCFswo.d.cts} +328 -14
  16. package/dist/{PackageRegistry-DT-x32OM.d.ts → PackageRegistry-CNZUwWHJ.d.ts} +328 -14
  17. package/dist/{Parselet-BawfGuTF.d.cts → Parselet-DF3864la.d.cts} +19 -3
  18. package/dist/{Parselet-DqTbbtWA.d.ts → Parselet-Dgymjxzd.d.ts} +19 -3
  19. package/dist/{Token-CbP_OutD.d.cts → Token-D8f7yaz1.d.cts} +17 -0
  20. package/dist/{Token-CbP_OutD.d.ts → Token-D8f7yaz1.d.ts} +17 -0
  21. package/dist/{TokenNormalizer-CLBtiE8M.d.ts → TokenNormalizer-IF7nPRMp.d.ts} +1 -1
  22. package/dist/{TokenNormalizer-CjTDmHgB.d.cts → TokenNormalizer-Pe3_390t.d.cts} +1 -1
  23. package/dist/{ScopeManager-B636am7Y.d.ts → VMBuiltins-CZiZRKn-.d.ts} +91 -9
  24. package/dist/{ScopeManager-CdwX0VTw.d.cts → VMBuiltins-kv4rr0y5.d.cts} +91 -9
  25. package/dist/{VMCheckpoints-DDlxNssY.d.ts → VMCheckpoints-DXze6ypg.d.ts} +2 -2
  26. package/dist/{VMCheckpoints-CYqeq8IV.d.cts → VMCheckpoints-yun4ocSv.d.cts} +2 -2
  27. package/dist/{Value-Ds3Gy07C.d.cts → Value-BYHw-x7q.d.cts} +57 -1
  28. package/dist/{Value-Ds3Gy07C.d.ts → Value-BYHw-x7q.d.ts} +57 -1
  29. package/dist/{WorkerError-B1dF3VYT.d.cts → WorkerError-BLZyNq6M.d.cts} +1 -1
  30. package/dist/{WorkerError-dneODN-u.d.ts → WorkerError-CfBJYueR.d.ts} +1 -1
  31. package/dist/chunk-2SYYKQ4Q.cjs +2 -0
  32. package/dist/chunk-2SYYKQ4Q.cjs.map +1 -0
  33. package/dist/chunk-6EYKVQT3.cjs +2 -0
  34. package/dist/chunk-6EYKVQT3.cjs.map +1 -0
  35. package/dist/chunk-7RC6RBS6.cjs +2 -0
  36. package/dist/chunk-7RC6RBS6.cjs.map +1 -0
  37. package/dist/chunk-AZX4NTYN.cjs +3 -0
  38. package/dist/chunk-AZX4NTYN.cjs.map +1 -0
  39. package/dist/{chunk-JFZ5SLF7.js → chunk-BCR53EIL.js} +2 -2
  40. package/dist/{chunk-JFZ5SLF7.js.map → chunk-BCR53EIL.js.map} +1 -1
  41. package/dist/chunk-BCY2WY5P.js +5 -0
  42. package/dist/chunk-BCY2WY5P.js.map +1 -0
  43. package/dist/chunk-BLJ6E577.js +2 -0
  44. package/dist/chunk-BLJ6E577.js.map +1 -0
  45. package/dist/chunk-CL7DM2FX.js +2 -0
  46. package/dist/chunk-CL7DM2FX.js.map +1 -0
  47. package/dist/{chunk-BMXYR5LI.cjs → chunk-CQLCTKMX.cjs} +2 -2
  48. package/dist/{chunk-BMXYR5LI.cjs.map → chunk-CQLCTKMX.cjs.map} +1 -1
  49. package/dist/chunk-D4VBWPWN.js +2 -0
  50. package/dist/chunk-D4VBWPWN.js.map +1 -0
  51. package/dist/chunk-DFMAZ6XM.cjs +3 -0
  52. package/dist/chunk-DFMAZ6XM.cjs.map +1 -0
  53. package/dist/chunk-E4HAKNBQ.cjs +2 -0
  54. package/dist/chunk-E4HAKNBQ.cjs.map +1 -0
  55. package/dist/{chunk-XHQYHXRE.js → chunk-ESZNJQ2C.js} +3 -3
  56. package/dist/{chunk-XHQYHXRE.js.map → chunk-ESZNJQ2C.js.map} +1 -1
  57. package/dist/{chunk-IJMNVBIS.js → chunk-FAO6DQ74.js} +2 -2
  58. package/dist/chunk-FAO6DQ74.js.map +1 -0
  59. package/dist/{chunk-WGP4UUO5.cjs → chunk-FDKTESBC.cjs} +2 -2
  60. package/dist/{chunk-WGP4UUO5.cjs.map → chunk-FDKTESBC.cjs.map} +1 -1
  61. package/dist/{chunk-NEGZZB7F.cjs → chunk-G2V33LFM.cjs} +2 -2
  62. package/dist/{chunk-NEGZZB7F.cjs.map → chunk-G2V33LFM.cjs.map} +1 -1
  63. package/dist/chunk-GJZIJK2Q.cjs +2 -0
  64. package/dist/chunk-GJZIJK2Q.cjs.map +1 -0
  65. package/dist/chunk-GVL3ZMS7.cjs +2 -0
  66. package/dist/chunk-GVL3ZMS7.cjs.map +1 -0
  67. package/dist/{chunk-YBQPEWT7.cjs → chunk-GXO7TSXQ.cjs} +3 -3
  68. package/dist/chunk-GXO7TSXQ.cjs.map +1 -0
  69. package/dist/{chunk-OONQ3V3I.js → chunk-HANGBVEE.js} +2 -2
  70. package/dist/{chunk-OONQ3V3I.js.map → chunk-HANGBVEE.js.map} +1 -1
  71. package/dist/chunk-J4K72CQN.js +2 -0
  72. package/dist/chunk-J4K72CQN.js.map +1 -0
  73. package/dist/{chunk-72PYPENZ.js → chunk-LE6WZLJ4.js} +2 -2
  74. package/dist/{chunk-72PYPENZ.js.map → chunk-LE6WZLJ4.js.map} +1 -1
  75. package/dist/chunk-LQIRBP4Q.js +2 -0
  76. package/dist/chunk-LQIRBP4Q.js.map +1 -0
  77. package/dist/{chunk-RDYXH7ML.js → chunk-LTUYWJGO.js} +2 -2
  78. package/dist/{chunk-RDYXH7ML.js.map → chunk-LTUYWJGO.js.map} +1 -1
  79. package/dist/chunk-O5PO4D2A.cjs +2 -0
  80. package/dist/chunk-O5PO4D2A.cjs.map +1 -0
  81. package/dist/chunk-PQFI55AC.js +3 -0
  82. package/dist/chunk-PQFI55AC.js.map +1 -0
  83. package/dist/chunk-QQHHZPEW.cjs +2 -0
  84. package/dist/chunk-QQHHZPEW.cjs.map +1 -0
  85. package/dist/chunk-REZQFPVX.js +2 -0
  86. package/dist/chunk-REZQFPVX.js.map +1 -0
  87. package/dist/chunk-RRUGQ6DM.js +2 -0
  88. package/dist/chunk-RRUGQ6DM.js.map +1 -0
  89. package/dist/chunk-S3ODNMJS.js +2 -0
  90. package/dist/chunk-S3ODNMJS.js.map +1 -0
  91. package/dist/{chunk-SAF3B3AX.cjs → chunk-SE6ZCGZ5.cjs} +2 -2
  92. package/dist/{chunk-SAF3B3AX.cjs.map → chunk-SE6ZCGZ5.cjs.map} +1 -1
  93. package/dist/chunk-TC23XEAV.js +2 -0
  94. package/dist/chunk-TC23XEAV.js.map +1 -0
  95. package/dist/{chunk-FYAMQFZZ.cjs → chunk-TMQ37JQY.cjs} +3 -3
  96. package/dist/{chunk-FYAMQFZZ.cjs.map → chunk-TMQ37JQY.cjs.map} +1 -1
  97. package/dist/chunk-TPPM4QSS.cjs +2 -0
  98. package/dist/chunk-TPPM4QSS.cjs.map +1 -0
  99. package/dist/chunk-UVHD7BBC.js +3 -0
  100. package/dist/{chunk-ZDCZ5IDD.js.map → chunk-UVHD7BBC.js.map} +1 -1
  101. package/dist/{chunk-57PSJQQW.js → chunk-VB6QMU2W.js} +3 -3
  102. package/dist/chunk-VB6QMU2W.js.map +1 -0
  103. package/dist/chunk-VQO54ZMA.js +2 -0
  104. package/dist/chunk-VQO54ZMA.js.map +1 -0
  105. package/dist/{chunk-7DP57BA7.js → chunk-Y7XRA2EV.js} +2 -2
  106. package/dist/{chunk-7DP57BA7.js.map → chunk-Y7XRA2EV.js.map} +1 -1
  107. package/dist/{chunk-5IJD5L3O.cjs → chunk-YBQOQTVL.cjs} +2 -2
  108. package/dist/chunk-YBQOQTVL.cjs.map +1 -0
  109. package/dist/{chunk-EL2XUOWX.js → chunk-YG7UWQFV.js} +2 -2
  110. package/dist/{chunk-EL2XUOWX.js.map → chunk-YG7UWQFV.js.map} +1 -1
  111. package/dist/chunk-YSHWNCDH.cjs +5 -0
  112. package/dist/chunk-YSHWNCDH.cjs.map +1 -0
  113. package/dist/chunk-ZC2NPRLO.js +3 -0
  114. package/dist/chunk-ZC2NPRLO.js.map +1 -0
  115. package/dist/{chunk-FYTB7SDP.cjs → chunk-ZDJTDFTR.cjs} +2 -2
  116. package/dist/{chunk-FYTB7SDP.cjs.map → chunk-ZDJTDFTR.cjs.map} +1 -1
  117. package/dist/chunk-ZE5KKMBV.cjs +2 -0
  118. package/dist/chunk-ZE5KKMBV.cjs.map +1 -0
  119. package/dist/{chunk-4BAUQE6A.cjs → chunk-ZPHUTCJ5.cjs} +3 -3
  120. package/dist/{chunk-4BAUQE6A.cjs.map → chunk-ZPHUTCJ5.cjs.map} +1 -1
  121. package/dist/{chunk-GBCN7FNV.cjs → chunk-ZSLVLMO5.cjs} +2 -2
  122. package/dist/{chunk-GBCN7FNV.cjs.map → chunk-ZSLVLMO5.cjs.map} +1 -1
  123. package/dist/constants.cjs +1 -1
  124. package/dist/constants.d.cts +1 -1
  125. package/dist/constants.d.ts +1 -1
  126. package/dist/constants.js +1 -1
  127. package/dist/engine.cjs +1 -1
  128. package/dist/engine.d.cts +14 -12
  129. package/dist/engine.d.ts +14 -12
  130. package/dist/engine.js +1 -1
  131. package/dist/errors.cjs +1 -1
  132. package/dist/errors.d.cts +3 -3
  133. package/dist/errors.d.ts +3 -3
  134. package/dist/errors.js +1 -1
  135. package/dist/format.cjs +1 -1
  136. package/dist/format.d.cts +4 -3
  137. package/dist/format.d.ts +4 -3
  138. package/dist/format.js +1 -1
  139. package/dist/index.cjs +1 -1
  140. package/dist/index.cjs.map +1 -1
  141. package/dist/index.d.cts +15 -13
  142. package/dist/index.d.ts +15 -13
  143. package/dist/index.js +1 -1
  144. package/dist/index.js.map +1 -1
  145. package/dist/language.d.cts +12 -11
  146. package/dist/language.d.ts +12 -11
  147. package/dist/lexer.cjs +1 -1
  148. package/dist/lexer.d.cts +4 -4
  149. package/dist/lexer.d.ts +4 -4
  150. package/dist/lexer.js +1 -1
  151. package/dist/normalizer.cjs +1 -1
  152. package/dist/normalizer.d.cts +3 -3
  153. package/dist/normalizer.d.ts +3 -3
  154. package/dist/normalizer.js +1 -1
  155. package/dist/packages.cjs +1 -1
  156. package/dist/packages.d.cts +11 -10
  157. package/dist/packages.d.ts +11 -10
  158. package/dist/packages.js +1 -1
  159. package/dist/parser.cjs +1 -1
  160. package/dist/parser.d.cts +5 -4
  161. package/dist/parser.d.ts +5 -4
  162. package/dist/parser.js +1 -1
  163. package/dist/{pipeline-69q2tsLE.d.cts → pipeline-BYkKNpql.d.cts} +1 -1
  164. package/dist/{pipeline-DTqGLPsV.d.ts → pipeline-Cl7KW8CB.d.ts} +1 -1
  165. package/dist/resolvers.d.cts +2 -2
  166. package/dist/resolvers.d.ts +2 -2
  167. package/dist/temporal.cjs +2 -0
  168. package/dist/temporal.cjs.map +1 -0
  169. package/dist/temporal.d.cts +201 -0
  170. package/dist/temporal.d.ts +201 -0
  171. package/dist/temporal.js +2 -0
  172. package/dist/temporal.js.map +1 -0
  173. package/dist/testing.cjs +2 -2
  174. package/dist/testing.cjs.map +1 -1
  175. package/dist/testing.d.cts +12 -11
  176. package/dist/testing.d.ts +12 -11
  177. package/dist/testing.js +1 -1
  178. package/dist/testing.js.map +1 -1
  179. package/dist/uom.cjs +1 -1
  180. package/dist/uom.d.cts +2 -2
  181. package/dist/uom.d.ts +2 -2
  182. package/dist/uom.js +1 -1
  183. package/dist/vm.cjs +1 -1
  184. package/dist/vm.cjs.map +1 -1
  185. package/dist/vm.d.cts +8 -56
  186. package/dist/vm.d.ts +8 -56
  187. package/dist/vm.js +1 -1
  188. package/dist/vm.js.map +1 -1
  189. package/dist/worker.cjs +2 -2
  190. package/dist/worker.cjs.map +1 -1
  191. package/dist/worker.d.cts +35 -13
  192. package/dist/worker.d.ts +35 -13
  193. package/dist/worker.js +2 -2
  194. package/dist/worker.js.map +1 -1
  195. package/package.json +12 -1
  196. package/dist/chunk-4BRTUFTH.js +0 -2
  197. package/dist/chunk-4BRTUFTH.js.map +0 -1
  198. package/dist/chunk-4NZXCHQL.cjs +0 -2
  199. package/dist/chunk-4NZXCHQL.cjs.map +0 -1
  200. package/dist/chunk-57PSJQQW.js.map +0 -1
  201. package/dist/chunk-5IJD5L3O.cjs.map +0 -1
  202. package/dist/chunk-634ILVMP.cjs +0 -2
  203. package/dist/chunk-634ILVMP.cjs.map +0 -1
  204. package/dist/chunk-63ZOOUOL.js +0 -2
  205. package/dist/chunk-63ZOOUOL.js.map +0 -1
  206. package/dist/chunk-77KI7AKJ.cjs +0 -2
  207. package/dist/chunk-77KI7AKJ.cjs.map +0 -1
  208. package/dist/chunk-7N3IJSWF.js +0 -5
  209. package/dist/chunk-7N3IJSWF.js.map +0 -1
  210. package/dist/chunk-DUYTXLO2.js +0 -2
  211. package/dist/chunk-DUYTXLO2.js.map +0 -1
  212. package/dist/chunk-IJMNVBIS.js.map +0 -1
  213. package/dist/chunk-JSM3O7EM.cjs +0 -2
  214. package/dist/chunk-JSM3O7EM.cjs.map +0 -1
  215. package/dist/chunk-MZMA32NE.js +0 -3
  216. package/dist/chunk-MZMA32NE.js.map +0 -1
  217. package/dist/chunk-N4SSR7Q6.js +0 -2
  218. package/dist/chunk-N4SSR7Q6.js.map +0 -1
  219. package/dist/chunk-NMU5E7W7.js +0 -2
  220. package/dist/chunk-NMU5E7W7.js.map +0 -1
  221. package/dist/chunk-OB2VX4IL.js +0 -2
  222. package/dist/chunk-OB2VX4IL.js.map +0 -1
  223. package/dist/chunk-RAPEZR5L.cjs +0 -2
  224. package/dist/chunk-RAPEZR5L.cjs.map +0 -1
  225. package/dist/chunk-SPOVFRZO.cjs +0 -5
  226. package/dist/chunk-SPOVFRZO.cjs.map +0 -1
  227. package/dist/chunk-SQHBOWES.cjs +0 -2
  228. package/dist/chunk-SQHBOWES.cjs.map +0 -1
  229. package/dist/chunk-UF5XMZTT.js +0 -2
  230. package/dist/chunk-UF5XMZTT.js.map +0 -1
  231. package/dist/chunk-UV3EUIBT.cjs +0 -3
  232. package/dist/chunk-UV3EUIBT.cjs.map +0 -1
  233. package/dist/chunk-VMSCRVNX.cjs +0 -2
  234. package/dist/chunk-VMSCRVNX.cjs.map +0 -1
  235. package/dist/chunk-XBGK3TTU.cjs +0 -3
  236. package/dist/chunk-XBGK3TTU.cjs.map +0 -1
  237. package/dist/chunk-XX55RR4Q.js +0 -3
  238. package/dist/chunk-XX55RR4Q.js.map +0 -1
  239. package/dist/chunk-YBQPEWT7.cjs.map +0 -1
  240. package/dist/chunk-ZDCZ5IDD.js +0 -3
@@ -0,0 +1,3 @@
1
+ import {a as a$1}from'./chunk-XEIDV5JP.js';import {g,D}from'./chunk-5TCSFTZD.js';import {Z as Z$1,R,ua,sa}from'./chunk-LTUYWJGO.js';import {b}from'./chunk-BLJ6E577.js';import {g as g$1,o,p}from'./chunk-J4K72CQN.js';import {m}from'./chunk-LQIRBP4Q.js';import {a}from'./chunk-LHLW7JLS.js';var M={floatResult:{decimalPlaces:2,enableSeperator:true},numberResult:{decimalSeparatorLocale:"en-US"},hexResult:{enablePadding:false,paddingZeros:0},unitOfMeasurementResult:{decimalPlaces:2},percentageResult:{decimalPlaces:2},dateResult:{format:"long"}};function A(t,e,r,o){let n=r.floatResult.enableSeperator,s=r.numberResult.decimalSeparatorLocale;if(o!==void 0&&Number.isFinite(t)){let c=t.toLocaleString(s||"en-US",{minimumFractionDigits:o,maximumFractionDigits:o,useGrouping:n});return `${e.display.resultPrefix}${c}`}let i=r.floatResult.decimalPlaces,a=a$1(t,i,n,s);return `${e.display.resultPrefix}${a}`}function O(t,e,r,o){let n=o.floatResult.decimalPlaces,s=o.floatResult.enableSeperator,i=o.numberResult.decimalSeparatorLocale||"en-US",a=Math.max(n,1),c=t.toLocaleString(i,{useGrouping:s,minimumFractionDigits:0,maximumFractionDigits:n}),l=Math.abs(e).toLocaleString(i,{useGrouping:s,minimumFractionDigits:1,maximumFractionDigits:a});return `${r.display.resultPrefix}${c} \xB1 ${l}`}function j(t,e,r){if(typeof t=="number"&&!Number.isFinite(t))return `= ${t}`;let o=typeof t=="bigint"?t<0n:t<0,n=o?"-":"",s=c=>typeof t=="bigint"?(o?-t:t).toString(c):Math.abs(Math.trunc(t)).toString(c);if(r==="bin")return `= ${n}0b${s(2)}`;if(r==="oct")return `= ${n}0o${s(8)}`;let i=e.hexResult.enablePadding?e.hexResult.paddingZeros:0,a=s(16).toUpperCase().padStart(i,"0");return `= ${n}0x${a}`}var k=2e4;function B(t){let e=t<0n?-t:t;if(Number.isFinite(Number(e)))return `= ${t}`;let r=e.toString(16).length*4;if(r*Math.LN2/Math.LN10<=k)return `= ${t}`;let o=r*Math.LN2/Math.LN10,n=Math.floor(o),s=Math.pow(10,o-n);return `= ${t<0n?"-":""}~${s.toFixed(3)}e+${n} (an exact integer of about ${(n+1).toLocaleString("en-US")} digits, too large to print)`}function G(t){return `= ${t}`}function _(t){return `= ${t}`}function Z(t,e,r,o$1){let n=r.calendar??b,s=r.dateResult?.format??"long",i=o$1!==void 0&&!g$1(o$1),a=i?n.fieldsInZone(o$1,t):n.fields(t),c=i?0:n.fields(t).millisecond,l=a.hour===0&&a.minute===0&&a.second===0&&c===0;if(s==="long"){let p$1=i?o(o$1,t,e.code):n.formatLongDate(t,e.code);if(l)return `= ${p$1}`;let E=i?p(o$1,t,e.code):n.formatTimeOfDay(t,e.code);return `= ${p$1}, ${E}`}let m=p=>String(p).padStart(2,"0"),u=a.year,g=m(a.month0+1),d=m(a.day),f;if(s==="iso"?f=`${u}-${g}-${d}`:s==="dmy"?f=`${d}/${g}/${u}`:f=`${g}/${d}/${u}`,l)return `= ${f}`;let S=`${m(a.hour)}:${m(a.minute)}:${m(a.second)}`;return s==="iso"?`= ${f}T${S}`:`= ${f} ${S}`}function V(t){let e=t<0?"-":"",r=Math.round(Math.abs(t)/1e3),o=Math.floor(r/3600),n=Math.floor(r%3600/60),s=r%60,i=String(n).padStart(2,"0");if(s===0)return `${e}${o}:${i}`;let a=String(s).padStart(2,"0");return `${e}${o}:${i}:${a}`}var w=new Map;function W(t){let e=w.get(t);return e===void 0&&(e=new Intl.NumberFormat(t).formatToParts(1.1).find(r=>r.type==="decimal")?.value??".",w.set(t,e)),e}function $(t,e,r){let o=/^(-?)(\d+)(?:\.(\d+))?$/.exec(t);if(!o)return t;let[,n,s,i]=o,a=r?BigInt(s).toLocaleString(e,{useGrouping:true}):s;return i===void 0?`${n}${a}`:`${n}${a}${W(e)}${i}`}function Y(t,e,r,o,n){if(e==="ms")return `= ${V(t)}`;e==="l100km"&&(e="l/100km"),e==="mps2"&&(e="m/s\xB2");let s=o.unitOfMeasurementResult.decimalPlaces,i=o.floatResult.enableSeperator,a=o.numberResult.decimalSeparatorLocale||"en-US",l=e&&["days","weeks","months","years","hours","minutes","seconds","day","week","month","year","hour","minute","second"].includes(e),m;l&&t===Math.floor(t)?m=$(t.toString(),a,i):m=$(t.toFixed(s),a,i);let u=e?ua[e.toUpperCase()]:void 0;if(u){let d=n?$(sa(n,s),a,i):m,f=u.spaced?" ":"";return `= ${u.position==="prefix"?`${u.symbol}${f}${d}`:`${d}${f}${u.symbol}`}`}return `= ${n?$(sa(n,s),a,i):m} ${e||""}`.trim()}function U(t,e){if(typeof t=="boolean")return t?"true":"false";if(typeof t=="object"&&t!==null)return R(t);let r=e.floatResult.decimalPlaces,o=e.floatResult.enableSeperator,n=e.numberResult.decimalSeparatorLocale;return a$1(t,r,o,n)}function H(t,e,r){let o=Z$1(t),n=[];for(let s=0;s<t.rows;s++){let i=[];for(let a=0;a<t.cols;a++)i.push(U(o[s*t.cols+a],r));n.push(i.join(", "));}return `${e.display.resultPrefix}[${n.join("; ")}]`}function gt(t,e){let r=e||M,o=Z$1(t),n=[];for(let i=0;i<t.rows;i++){let a=[];for(let c=0;c<t.cols;c++)a.push(U(o[i*t.cols+c],r));n.push(a);}let s=[];for(let i=0;i<t.cols;i++){let a=0;for(let c=0;c<t.rows;c++)a=Math.max(a,n[c][i].length);s.push(a);}return n.map(i=>`[ ${i.map((a,c)=>a.padStart(s[c])).join(" ")} ]`).join(`
2
+ `)}function X(t,e,r){return `${r.display.resultPrefix}${t}:${e}`}function q(t,e,r){let o=r.percentageResult.decimalPlaces;return `= ${(t*100).toFixed(o)}${e.display.percentageSuffix}`}function J(t,e){return `= ${t} ${e||""}`.trim()}function K(t){if(t.addr===void 0)return `/${t.prefix}`;let e=D(t.addr);return t.prefix===void 0?e:`${e}/${t.prefix}`}function Q(t,e,r){let o=e.display.resultPrefix,n=l=>{let m$1=t.unit!==void 0?new m(6,l.value,t.unit):new m(0,l.value);m$1.exact=l.exact;let u=z(m$1,r);return u.startsWith(o)?u.slice(o.length):u},[s,i]=t.shares,a=`${n(s)} each`;if(i===void 0)return `${o}${a}`;let c=i.count===1?"share":"shares";return `${o}${a}, with ${i.count} ${c} paying ${n(i)}`}function z(t,e){let r=e||M,o=r.numberResult.decimalSeparatorLocale||"en",n=a(o);switch(t.type){case 0:return t.uncertainty!==void 0?O(t.value,t.uncertainty,n,r):A(t.value,n,r,t.decimalPlaces);case 1:return j(t.value,r,t.unit);case 2:return B(t.value);case 3:return G(t.value);case 10:return _(t.value);case 4:return Z(t.value,n,r,t.zone);case 6:return Y(t.value,t.unit,n,r,t.exact);case 7:return H(t.value,n,r);case 8:{let s=t.value;return X(s.min,s.max,n)}case 14:return `${n.display.resultPrefix}${g(t.value)}`;case 15:return Q(t.value,n,r);case 16:return `${n.display.resultPrefix}${t.value.label}`;case 17:return `${n.display.resultPrefix}${K(t.value)}`;case 9:return R(t.value);case 5:return q(t.value,n,r);case 11:return J(t.value,t.unit);case 13:return t.unit??String(t.value);default:return `= ${String(t.value)}`}}export{M as a,gt as b,z as c};//# sourceMappingURL=chunk-ZC2NPRLO.js.map
3
+ //# sourceMappingURL=chunk-ZC2NPRLO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/format/FormattingSettings.ts","../src/format/FormatEngine.ts"],"names":["DEFAULT_FORMATTING_SETTINGS","formatNumber","value","locale","settings","decimalPlaces","sep","loc","formatted","dp","autoFormatIntegerOrFloat","formatUncertain","center","uncertainty","useGrouping","spreadMax","centerText","spreadText","formatHex","base","negative","sign","digits","radix","padding","hex","MAX_DISPLAYED_BIGINT_DIGITS","formatBigInt","magnitude","bits","log10","exponent","mantissa","formatString","formatBoolean","formatDatetime","zone","calendar","DATE_CALENDAR","format","named","isFixedOffset","d","millisecond","isMidnight","dateStr","longDateInZone","timeStr","timeOfDayInZone","p2","n","year","month","day","datePart","time","formatMsDuration","ms","totalSeconds","hours","minutes","seconds","mm","ss","decimalMarkByLocale","decimalMark","mark","part","localiseFixedDecimal","fixed","match","integer","fraction","integerText","formatUom","unit","exact","isTimeSpan","currencyDisplay","CURRENCY_DISPLAY","moneyText","decimalToFixed","formatMatrixEntry","entry","formatSymbolic","formatMatrix","m","rowMajor","columnMajorToRowMajor","rows","r","cells","c","formatMatrixAligned","us","row","colWidth","width","cell","formatRange","min","max","formatPercentage","formatUnit","formatIpCidr","data","dotted","formatIp","formatSplit","prefix","render","share","v","Value","text","formatValue","high","each","shareWord","localeCode","getLocale","formatColour"],"mappings":"+RA2DO,IAAMA,CAAAA,CAAkD,CAC7D,WAAA,CAAa,CACX,aAAA,CAAe,CAAA,CACf,eAAA,CAAiB,IACnB,CAAA,CACA,YAAA,CAAc,CACZ,sBAAA,CAAwB,OAC1B,CAAA,CACA,SAAA,CAAW,CACT,aAAA,CAAe,KAAA,CACf,YAAA,CAAc,CAChB,CAAA,CACA,wBAAyB,CACvB,aAAA,CAAe,CACjB,CAAA,CACA,gBAAA,CAAkB,CAChB,aAAA,CAAe,CACjB,EACA,UAAA,CAAY,CACV,MAAA,CAAQ,MACV,CACF,ECnEA,SAASC,CAAAA,CAAaC,CAAAA,CAAeC,CAAAA,CAAiBC,CAAAA,CAA8BC,CAAAA,CAAgC,CAClH,IAAMC,CAAAA,CAAMF,CAAAA,CAAS,YAAY,eAAA,CAC3BG,CAAAA,CAAMH,CAAAA,CAAS,YAAA,CAAa,sBAAA,CAMlC,GAAIC,CAAAA,GAAkB,MAAA,EAAa,OAAO,QAAA,CAASH,CAAK,CAAA,CAAG,CACzD,IAAMM,CAAAA,CAAYN,CAAAA,CAAM,cAAA,CAAeK,GAAO,OAAA,CAAS,CACrD,qBAAA,CAAuBF,CAAAA,CACvB,qBAAA,CAAuBA,CAAAA,CACvB,WAAA,CAAaC,CACf,CAAC,CAAA,CACD,OAAO,CAAA,EAAGH,CAAAA,CAAO,OAAA,CAAQ,YAAY,CAAA,EAAGK,CAAS,CAAA,CACnD,CACA,IAAMC,CAAAA,CAAKL,CAAAA,CAAS,WAAA,CAAY,aAAA,CAC1BI,CAAAA,CAAYE,IAAyBR,CAAAA,CAAOO,CAAAA,CAAIH,CAAAA,CAAKC,CAAG,CAAA,CAC9D,OAAO,CAAA,EAAGJ,CAAAA,CAAO,QAAQ,YAAY,CAAA,EAAGK,CAAS,CAAA,CACnD,CAk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EAAavH,CAAAA,CAAM,KAAmB,CAAC,CAAA,CAAA,CACjF,KAAA,EAAA,CACE,OAAO0G,CAAAA,CAAY1G,CAAAA,CAAM,MAAoBC,CAAAA,CAAQ2F,CAAE,EACzD,KAAA,EAAA,CAGE,OAAO,GAAG3F,CAAAA,CAAO,OAAA,CAAQ,YAAY,CAAA,EAAID,CAAAA,CAAM,MAAoB,KAAK,CAAA,CAAA,CAC1E,QACE,OAAO,CAAA,EAAGC,EAAO,OAAA,CAAQ,YAAY,GAAGqG,CAAAA,CAAatG,CAAAA,CAAM,KAAmB,CAAC,CAAA,CAAA,CACjF,OACE,OAAOkF,CAAAA,CAAelF,EAAM,KAAqB,CAAA,CACnD,OACE,OAAOoG,CAAAA,CAAiBpG,EAAM,KAAA,CAAiBC,CAAAA,CAAQ2F,CAAE,CAAA,CAC3D,KAAA,EAAA,CACE,OAAOS,CAAAA,CAAWrG,CAAAA,CAAM,MAAiBA,CAAAA,CAAM,IAAI,EACrD,KAAA,EAAA,CAKE,OAAOA,EAAM,IAAA,EAAQ,MAAA,CAAOA,EAAM,KAAK,CAAA,CACzC,QACE,OAAO,CAAA,EAAA,EAAK,OAAOA,CAAAA,CAAM,KAAK,CAAC,CAAA,CACnC,CACF","file":"chunk-ZC2NPRLO.js","sourcesContent":["import type { CalendarBackend } from \"@solve-js/calendar/CalendarBackend\";\n/**\n * How a Datetime value is rendered.\n *\n * - `'long'`: the spelled-out form, \"Tuesday, March 10, 2026\" (the default).\n * - `'iso'`: \"2026-03-10\" (ISO 8601, with a `T`-separated time when present).\n * - `'dmy'`: \"10/03/2026\" (day first).\n * - `'mdy'`: \"03/10/2026\" (month first).\n *\n * The weekday and long month name in `'long'` are localised through the same\n * locale the number separators come from; the numeric forms are locale-neutral.\n */\nexport type DateOutputFormat = \"long\" | \"iso\" | \"dmy\" | \"mdy\";\n\n/**\n * Minimal formatting settings interface for the engine\n * This allows the engine to format values without depending on app-specific settings\n */\nexport interface FormattingSettings {\n /**\n * The calendar backend a date is written out through: which local day and\n * wall-clock time an instant shows as. Pass the same backend the engine\n * was given as its `calendar` option, so a date displays in the zone it\n * was computed in. Absent means the built-in `Date` backend, the process's\n * own zone, which is what every engine computes with by default.\n *\n * A backend is an object of functions, so it cannot cross a `postMessage`\n * boundary: a worker runtime takes its backend from `WorkerRuntimeOptions`\n * and applies it to the formatting it receives.\n */\n calendar?: CalendarBackend;\n floatResult: {\n decimalPlaces: number;\n enableSeperator: boolean;\n };\n numberResult: {\n decimalSeparatorLocale: string;\n };\n hexResult: {\n enablePadding: boolean;\n paddingZeros: number;\n };\n unitOfMeasurementResult: {\n decimalPlaces: number;\n };\n percentageResult: {\n decimalPlaces: number;\n };\n /**\n * Optional so a host that built a `FormattingSettings` before this field\n * existed still compiles; a missing `dateResult` reads as `'long'`, the\n * historic output.\n */\n dateResult?: {\n format: DateOutputFormat;\n };\n}\n\n/** Formatting used when a host supplies none. */\nexport const DEFAULT_FORMATTING_SETTINGS: FormattingSettings = {\n floatResult: {\n decimalPlaces: 2,\n enableSeperator: true,\n },\n numberResult: {\n decimalSeparatorLocale: \"en-US\",\n },\n hexResult: {\n enablePadding: false,\n paddingZeros: 0,\n },\n unitOfMeasurementResult: {\n decimalPlaces: 2,\n },\n percentageResult: {\n decimalPlaces: 2,\n },\n dateResult: {\n format: \"long\",\n },\n};\n","import { Value, ValueType, type MatrixData, type MatrixEntry, type RangeData, type ColourData, type SplitData, type SplitShare, type ChartData, type IpCidrData } from \"@solve-js/vm/Value\";\nimport { formatColour } from \"@solve-js/packages/colour/ColourMath\";\nimport { formatIp } from \"@solve-js/packages/ip/IpMath\";\nimport { decimalToFixed, type DecimalData } from \"@solve-js/decimal\";\nimport { getLocale, type ILocale } from \"@solve-js/constants/locales\";\nimport { autoFormatIntegerOrFloat } from \"@solve-js/utilities/Number\";\nimport { FormattingSettings, DEFAULT_FORMATTING_SETTINGS } from \"./FormattingSettings\";\nimport { CURRENCY_DISPLAY } from \"@solve-js/uom/CurrencyAliases\";\nimport { columnMajorToRowMajor } from \"@solve-js/vm/MatrixOps\";\nimport { formatSymbolic, type SymbolicNode } from \"@solve-js/symbolic\";\nimport { DATE_CALENDAR } from \"@solve-js/calendar/DateCalendar\";\nimport { isFixedOffset, longDateInZone, timeOfDayInZone } from \"@solve-js/calendar/IntlZone\";\n\nfunction formatNumber(value: number, locale: ILocale, settings: FormattingSettings, decimalPlaces?: number): string {\n const sep = settings.floatResult.enableSeperator;\n const loc = settings.numberResult.decimalSeparatorLocale;\n // An explicit precision (`3.14159 to 4 dp`, `round(1.5, 2)`) shows EXACTLY that\n // many places with trailing zeros kept, where the default trims them and shows\n // an integer with none. The value was already rounded to this precision when\n // it was set (see VMBuiltins' roundToPlaces, exact where an exact decimal was\n // there), so rendering it to the same place count reproduces that rounding.\n if (decimalPlaces !== undefined && Number.isFinite(value)) {\n const formatted = value.toLocaleString(loc || \"en-US\", {\n minimumFractionDigits: decimalPlaces,\n maximumFractionDigits: decimalPlaces,\n useGrouping: sep,\n });\n return `${locale.display.resultPrefix}${formatted}`;\n }\n const dp = settings.floatResult.decimalPlaces;\n const formatted = autoFormatIntegerOrFloat(value, dp, sep, loc);\n return `${locale.display.resultPrefix}${formatted}`;\n}\n\n/**\n * Renders a measurement that carries a one-sigma uncertainty as\n * `center ± spread`, e.g. `49.2 ± 2.0`.\n *\n * The center is shown the way any number is, whole numbers as integers and\n * trailing zeros trimmed, so a tolerance-free-looking center still reads\n * cleanly (\"30 ± 2.24\", not \"30.00 ± 2.24\"). The spread is shown to the same\n * decimal-place budget but always keeps at least one fractional digit, which is\n * what distinguishes it as a tolerance and gives \"± 2.0\" rather than \"± 2\".\n * Both use `Intl` with `maximumFractionDigits`, so the trailing-zero trimming is\n * locale-correct (a comma-decimal locale is not string-sliced on \".\").\n *\n * The symbol is always the `±` glyph on output, even when the input was the\n * ASCII `+/-`, since the glyph is the conventional notation and unambiguous to\n * read back.\n */\nfunction formatUncertain(center: number, uncertainty: number, locale: ILocale, settings: FormattingSettings): string {\n const dp = settings.floatResult.decimalPlaces;\n const useGrouping = settings.floatResult.enableSeperator;\n const loc = settings.numberResult.decimalSeparatorLocale || \"en-US\";\n // The spread needs room for at least one fractional digit, so a zero-decimal\n // budget cannot leave minimumFractionDigits above maximumFractionDigits.\n const spreadMax = Math.max(dp, 1);\n const centerText = center.toLocaleString(loc, { useGrouping, minimumFractionDigits: 0, maximumFractionDigits: dp });\n const spreadText = Math.abs(uncertainty).toLocaleString(loc, { useGrouping, minimumFractionDigits: 1, maximumFractionDigits: spreadMax });\n return `${locale.display.resultPrefix}${centerText} ± ${spreadText}`;\n}\n\n/**\n * Renders a number in whichever base it is tagged with.\n *\n * The zero padding is a hexadecimal setting and stays one. Applying it to a\n * binary rendering would pad `0b101` out to the same digit count as a hex\n * value, which is a different quantity of zeros and not what the setting asks\n * for.\n */\nfunction formatHex(value: number | bigint, settings: FormattingSettings, base?: string): string {\n // An infinity or a NaN has no digits in any base, and asking for them\n // produced `0xINFINITY`, a literal that reads back as nothing at all. Render\n // the value itself, which is what every other non-finite result shows.\n if (typeof value === \"number\" && !Number.isFinite(value)) return `= ${value}`;\n\n // Truncate and take the sign off before converting. `Number.toString(radix)`\n // does neither: it renders -255 as \"-ff\", which lands the minus inside the\n // literal as `0x-FF`, and it renders 255.7 as \"ff.b3333333333\", inventing\n // fractional hex digits for a notation that has no use for them. Both were\n // visible on `as hex` until the builtins started sharing this path.\n //\n // A bigint needs neither truncation nor a Math call, and must not be routed\n // through one: passing it to Math.trunc() throws, and converting it to a\n // double first is exactly the precision loss it is carried as a bigint to\n // avoid.\n const negative = typeof value === \"bigint\" ? value < 0n : value < 0;\n const sign = negative ? \"-\" : \"\";\n const digits = (radix: number): string =>\n typeof value === \"bigint\"\n ? (negative ? -value : value).toString(radix)\n : Math.abs(Math.trunc(value)).toString(radix);\n\n if (base === \"bin\") return `= ${sign}0b${digits(2)}`;\n if (base === \"oct\") return `= ${sign}0o${digits(8)}`;\n const padding = settings.hexResult.enablePadding ? settings.hexResult.paddingZeros : 0;\n const hex = digits(16).toUpperCase().padStart(padding, \"0\");\n return `= ${sign}0x${hex}`;\n}\n\n/**\n * How many decimal digits of an exact integer this will render in full.\n *\n * A little above the ~19,729 digits of the largest bigint the VM will build\n * (`vm/VM.ts`'s MAX_EXACT_POW_BITS / MAX_EXACT_SHIFT_BITS, 65,536 bits), so\n * every value the engine can produce through `^` or `<<` still prints exactly\n * and this ceiling only ever meets a value that came from somewhere else.\n */\nconst MAX_DISPLAYED_BIGINT_DIGITS = 20000;\n\n/**\n * Renders an exact integer, or describes it when writing it out is itself the\n * expensive operation.\n *\n * This used to be a bare `= ${value}` template, which renders whatever it is\n * handed: `1n << 100000000` took 8.5 seconds here turning a 12.5MB integer\n * into a thirty-million-character string, and a host has no way to opt out,\n * since displaying the answer is what it asked the engine for. The VM's own\n * ceiling on `<<` and `^` now stops that value existing, so this is the\n * backstop for every other way a large bigint can arrive (repeated `x * x`,\n * a Value a host built itself), and it costs one comparison for every value\n * that is not absurd.\n *\n * The digit count is estimated from the bit length rather than measured, since\n * measuring means doing the conversion this exists to avoid. Bit length comes\n * off the hexadecimal form, which is linear in the size of the value where the\n * decimal form is not.\n */\nfunction formatBigInt(value: bigint): string {\n const magnitude = value < 0n ? -value : value;\n // Every bigint a person actually reads takes this line and nothing else:\n // anything a double can hold is at most 309 digits, so it is printable\n // without measuring it at all.\n if (Number.isFinite(Number(magnitude))) return `= ${value}`;\n const bits = magnitude.toString(16).length * 4;\n if (bits * Math.LN2 / Math.LN10 <= MAX_DISPLAYED_BIGINT_DIGITS) return `= ${value}`;\n const log10 = bits * Math.LN2 / Math.LN10;\n const exponent = Math.floor(log10);\n const mantissa = Math.pow(10, log10 - exponent);\n const sign = value < 0n ? \"-\" : \"\";\n return `= ${sign}~${mantissa.toFixed(3)}e+${exponent} (an exact integer of about ${(exponent + 1).toLocaleString(\"en-US\")} digits, too large to print)`;\n}\n\nfunction formatString(value: string): string {\n return `= ${value}`;\n}\n\nfunction formatBoolean(value: boolean): string {\n return `= ${value}`;\n}\n\n/**\n * Renders a Datetime value locale-aware, the previous implementation\n * called `d.toLocaleString()` with no arguments, which always uses the JS\n * runtime's own default locale and never actually consulted `locale.code`\n * despite receiving it as a parameter (both branches of its old\n * `dateFormat === \"default\"` check were byte-for-byte identical, dead\n * groundwork for a distinction that was never implemented). Concretely,\n * this meant every configured locale (including the shipped German one)\n * always displayed weekday/month names in English. See GitHub issue #77.\n *\n * Uses `weekday`/`month`: \"long\" for a spelled-out date (\"Monday,\n * November 17, 2025\" / \"lundi 17 novembre 2025\") since that's what a\n * literal weekday name is for; a bare numeric date doesn't need\n * localizing beyond the decimal/thousands separators `formatNumber()`\n * already handles. The time-of-day portion is only appended when it's\n * not exactly local midnight, bare date literals (\"today\", \"17/11/2025\")\n * always anchor to local midnight, and showing \"00:00:00\" on every one of\n * those would be noise, not information.\n *\n * Reads the calendar backend on the settings, or the built-in `Date` one\n * when the settings name none: `formatValue` is a free function a host calls\n * with a value and settings, with no engine in hand, so the host passes the\n * backend its engine computes with (`FormattingSettings.calendar`) and a\n * date shows the day it was computed on, in that backend's zone.\n */\nfunction formatDatetime(value: number, locale: ILocale, settings: FormattingSettings, zone?: string): string {\n const calendar = settings.calendar ?? DATE_CALENDAR;\n const format = settings.dateResult?.format ?? \"long\";\n\n // A date that names a zone is read in it. `3 April 2026 in Tokyo` is Tokyo's\n // 3 April, and rendering the instant behind it in the reader's own zone\n // showed them 2 April: the right moment, answering a question nobody asked.\n //\n // Only a named zone, deliberately. An ISO literal carrying `Z` or an offset\n // records the synthetic fixed-offset form, and how those display is a\n // separate question this does not answer: they keep reading in the zone the\n // engine computes in, as they always have.\n const named = zone !== undefined && !isFixedOffset(zone);\n const d = named ? calendar.fieldsInZone(zone, value) : calendar.fields(value);\n const millisecond = named ? 0 : calendar.fields(value).millisecond;\n const isMidnight = d.hour === 0 && d.minute === 0 && d.second === 0 && millisecond === 0;\n\n // The spelled-out default, localised through the locale's own names.\n if (format === \"long\") {\n const dateStr = named ? longDateInZone(zone, value, locale.code) : calendar.formatLongDate(value, locale.code);\n if (isMidnight) return `= ${dateStr}`;\n const timeStr = named ? timeOfDayInZone(zone, value, locale.code) : calendar.formatTimeOfDay(value, locale.code);\n return `= ${dateStr}, ${timeStr}`;\n }\n\n // The numeric forms, built from the local calendar fields so they read the\n // same regardless of the JS runtime's own default locale.\n const p2 = (n: number) => String(n).padStart(2, \"0\");\n const year = d.year;\n const month = p2(d.month0 + 1);\n const day = p2(d.day);\n let datePart: string;\n if (format === \"iso\") datePart = `${year}-${month}-${day}`;\n else if (format === \"dmy\") datePart = `${day}/${month}/${year}`;\n else datePart = `${month}/${day}/${year}`; // mdy\n\n if (isMidnight) return `= ${datePart}`;\n const time = `${p2(d.hour)}:${p2(d.minute)}:${p2(d.second)}`;\n // ISO joins date and time with `T`; the slash forms with a space.\n return format === \"iso\" ? `= ${datePart}T${time}` : `= ${datePart} ${time}`;\n}\n\n/**\n * Renders a millisecond duration as clock-style `H:MM` (or `H:MM:SS` when\n * there's a non-zero seconds component). `ms` is never a user-typeable\n * unit (confirmed: it appears nowhere in `lexer/units.ts`), it's only\n * ever produced by subtracting two clock times/datetimes (`9:30 - 8:30`,\n * `VM.ts`'s Datetime SUB case), so this is a safe, narrow special case,\n * not a general change to how durations display.\n */\nfunction formatMsDuration(ms: number): string {\n const sign = ms < 0 ? \"-\" : \"\";\n const totalSeconds = Math.round(Math.abs(ms) / 1000);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n const mm = String(minutes).padStart(2, \"0\");\n if (seconds === 0) return `${sign}${hours}:${mm}`;\n const ss = String(seconds).padStart(2, \"0\");\n return `${sign}${hours}:${mm}:${ss}`;\n}\n\n/** The decimal mark each locale writes, looked up once per locale rather than on every value. */\nconst decimalMarkByLocale = new Map<string, string>();\n\nfunction decimalMark(loc: string): string {\n let mark = decimalMarkByLocale.get(loc);\n if (mark === undefined) {\n mark = new Intl.NumberFormat(loc).formatToParts(1.1).find((part) => part.type === \"decimal\")?.value ?? \".\";\n decimalMarkByLocale.set(loc, mark);\n }\n return mark;\n}\n\n/**\n * Write a fixed-decimal string (`\"1234567.50\"`) the way `loc` writes numbers:\n * its decimal mark, and its digit grouping when `useGrouping` is on.\n *\n * Every quantity and every money amount used to be rendered with a bare\n * `toFixed`, so a plain `52000` showed as `52,000` while `£52000` showed as\n * `£52000.00`, and the `enableSeperator` setting had no effect on the one\n * value type people most want grouped. The digits are taken from the string\n * rather than re-rendered from the double, because an exact money amount has\n * already been rounded from its decimal (see {@link formatUom}) and\n * re-rendering would undo that. `BigInt` carries the integer part through\n * `Intl` so grouping follows the locale's own rule (Indian lakhs included)\n * rather than a hand-written every-three-digits. Anything that is not plain\n * digits, an `Infinity` or an exponent form, is returned as it came.\n */\nfunction localiseFixedDecimal(fixed: string, loc: string, useGrouping: boolean): string {\n const match = /^(-?)(\\d+)(?:\\.(\\d+))?$/.exec(fixed);\n if (!match) return fixed;\n const [, sign, integer, fraction] = match;\n const integerText = useGrouping ? BigInt(integer).toLocaleString(loc, { useGrouping: true }) : integer;\n if (fraction === undefined) return `${sign}${integerText}`;\n return `${sign}${integerText}${decimalMark(loc)}${fraction}`;\n}\n\nfunction formatUom(value: number, unit: string | undefined, locale: ILocale, settings: FormattingSettings, exact?: DecimalData): string {\n if (unit === \"ms\") return `= ${formatMsDuration(value)}`;\n // A fuel-consumption unit is stored slash-free (so it is not read as a rate)\n // but shown the way it is written.\n if (unit === \"l100km\") unit = \"l/100km\";\n if (unit === \"mps2\") unit = \"m/s²\";\n\n const dp = settings.unitOfMeasurementResult.decimalPlaces;\n const useGrouping = settings.floatResult.enableSeperator;\n const loc = settings.numberResult.decimalSeparatorLocale || \"en-US\";\n\n // For TimeSpan values (days, weeks, hours, etc.), format as integer if the value is a whole number\n const timeSpanUnits = [\"days\", \"weeks\", \"months\", \"years\", \"hours\", \"minutes\", \"seconds\", \"day\", \"week\", \"month\", \"year\", \"hour\", \"minute\", \"second\"];\n const isTimeSpan = unit && timeSpanUnits.includes(unit);\n\n let formatted: string;\n if (isTimeSpan && value === Math.floor(value)) {\n // For whole number TimeSpan values, format as integer\n formatted = localiseFixedDecimal(value.toString(), loc, useGrouping);\n } else {\n // For other values, use the configured decimal places\n formatted = localiseFixedDecimal(value.toFixed(dp), loc, useGrouping);\n }\n\n // Currency display: symbol + culturally-conventional placement (e.g.\n // \"$100.00\" prefix vs \"100.00 kr\" suffix) instead of the generic\n // \"amount CODE\" fallback below. See uom/CurrencyAliases.ts's\n // CURRENCY_DISPLAY table for the exact set covered and the reasoning\n // behind each placement choice. Any currency code NOT in that table\n // (most of the ~150 `CurrencyExchange.isCurrency()` recognizes) falls\n // through to the unchanged \"amount CODE\" format below.\n const currencyDisplay = unit ? CURRENCY_DISPLAY[unit.toUpperCase()] : undefined;\n if (currencyDisplay) {\n // An exact money amount rounds from its decimal, not from the double: a\n // half-cent like \"$1.005\" reads as \"$1.01\" here, where \"(1.005).toFixed(2)\"\n // answers \"1.00\" because the double it is handed already sits below the\n // value the user typed. Amounts with no exact decimal (a currency\n // conversion, whose rate is a double) keep the toFixed rendering above.\n const moneyText = exact ? localiseFixedDecimal(decimalToFixed(exact, dp), loc, useGrouping) : formatted;\n const sep = currencyDisplay.spaced ? \" \" : \"\";\n const withSymbol = currencyDisplay.position === \"prefix\"\n ? `${currencyDisplay.symbol}${sep}${moneyText}`\n : `${moneyText}${sep}${currencyDisplay.symbol}`;\n return `= ${withSymbol}`;\n }\n\n // The unit is written as the symbol the value carries. There used to be a\n // `unitOfMeasurementResult.unitNames` setting here whose two branches were\n // the same expression, so it never changed anything, and it was removed\n // rather than implemented: the engine has no unit-name data to render from.\n // The generated unit table maps a spelling to [measure, ratio] only, and\n // names cannot be recovered from it, because units that differ by an OFFSET\n // share a ratio, so \"20 C\" would come back as \"20 kelvins\". A real\n // implementation needs a hand-authored name per unit plus pluralization and\n // per-locale spelling (metre against meter), which is a feature rather than\n // the repair of a dead ternary.\n //\n // An exact currency with no symbol in the display table above (one of the\n // less common ISO codes) still rounds from its decimal here, so \"1.005 UYW\"\n // reads the same way \"$1.005\" does. Non-currency Uoms never carry an exact,\n // so this leaves \"1.50 kg\" exactly as it was.\n const genericText = exact ? localiseFixedDecimal(decimalToFixed(exact, dp), loc, useGrouping) : formatted;\n return `= ${genericText} ${unit || \"\"}`.trim();\n}\n\nfunction formatMatrixEntry(entry: MatrixEntry, settings: FormattingSettings): string {\n if (typeof entry === \"boolean\") return entry ? \"true\" : \"false\";\n if (typeof entry === \"object\" && entry !== null) return formatSymbolic(entry);\n const dp = settings.floatResult.decimalPlaces;\n const sep = settings.floatResult.enableSeperator;\n const loc = settings.numberResult.decimalSeparatorLocale;\n return autoFormatIntegerOrFloat(entry, dp, sep, loc);\n}\n\n/**\n * Renders a Matrix matching its own literal syntax: a single row (1xN,\n * including plain vectors) as `[a, b, c]`, a single column (Nx1) as\n * `[a; b; c]`, and a general shape as `[r0c0, r0c1; r1c0, r1c1]`, row-major\n * textual output read back out of the column-major storage\n * (`columnMajorToRowMajor()`), matching how `[1,2;3,4]` is written.\n */\nfunction formatMatrix(m: MatrixData, locale: ILocale, settings: FormattingSettings): string {\n const rowMajor = columnMajorToRowMajor(m);\n const rows: string[] = [];\n for (let r = 0; r < m.rows; r++) {\n const cells: string[] = [];\n for (let c = 0; c < m.cols; c++) {\n cells.push(formatMatrixEntry(rowMajor[r * m.cols + c], settings));\n }\n rows.push(cells.join(\", \"));\n }\n return `${locale.display.resultPrefix}[${rows.join(\"; \")}]`;\n}\n\n/**\n * Render a matrix as a multi-line, column-aligned block: one row per line (the\n * newline is where {@link formatValue}'s compact form writes `;`), each column\n * right-padded to its widest cell, and every row wrapped in `[ ... ]`. For\n * display where a grid reads better than a line, e.g. a docs notepad or a REPL:\n *\n * ```text\n * [ 1 2 ]\n * [ 30 4 ]\n * ```\n *\n * This is deliberately separate from {@link formatValue}, whose single-line\n * matrix form stays the stable, assertable text the API and the worker DTO use.\n * A 1xN row vector is one line; an Nx1 column vector is N lines.\n */\nexport function formatMatrixAligned(m: MatrixData, settings?: FormattingSettings): string {\n const us = settings || DEFAULT_FORMATTING_SETTINGS;\n const rowMajor = columnMajorToRowMajor(m);\n const cells: string[][] = [];\n for (let r = 0; r < m.rows; r++) {\n const row: string[] = [];\n for (let c = 0; c < m.cols; c++) {\n row.push(formatMatrixEntry(rowMajor[r * m.cols + c], us));\n }\n cells.push(row);\n }\n const colWidth: number[] = [];\n for (let c = 0; c < m.cols; c++) {\n let width = 0;\n for (let r = 0; r < m.rows; r++) width = Math.max(width, cells[r][c].length);\n colWidth.push(width);\n }\n return cells\n .map((row) => `[ ${row.map((cell, c) => cell.padStart(colWidth[c])).join(\" \")} ]`)\n .join(\"\\n\");\n}\n\nfunction formatRange(min: number, max: number, locale: ILocale): string {\n return `${locale.display.resultPrefix}${min}:${max}`;\n}\n\nfunction formatPercentage(value: number, locale: ILocale, settings: FormattingSettings): string {\n // ValueType.Percentage stores a fraction (0.25 for 25%). See Value.ts's\n // documented contract and the sole producer, VM.ts's TO_PERCENTAGE opcode\n // (`right/left - 1`, e.g. 0.25 for \"800 to 1000\"). Multiply by 100 before\n // formatting; without this every percentage-change result displayed as\n // e.g. \"0.25%\" instead of \"25.00%\".\n const dp = settings.percentageResult.decimalPlaces;\n const formatted = (value * 100).toFixed(dp);\n return `= ${formatted}${locale.display.percentageSuffix}`;\n}\n\nfunction formatUnit(value: number, unit: string | undefined): string {\n return `= ${value} ${unit || \"\"}`.trim();\n}\n\n/**\n * Renders a per-person bill split: \"= $45.00 each\", or, when the division is\n * uneven, \"= $33.33 each, with 1 share paying $33.34\". Each share's amount is\n * rendered through the ordinary value formatter (a throwaway {@link Value}), so\n * a currency share honours the same symbol placement, decimal places and locale\n * as any other money and a bare share trims trailing zeros the way a plain\n * number does; the \"= \" prefix is added once, around the whole sentence, not\n * per share.\n */\n/**\n * An IP/CIDR as text: the dotted quad, plus `/prefix` when present, or a bare\n * `/prefix` when there is no address (`netmask of /24` before it resolves).\n */\nfunction formatIpCidr(data: IpCidrData): string {\n\tif (data.addr === undefined) return `/${data.prefix}`;\n\tconst dotted = formatIp(data.addr);\n\treturn data.prefix === undefined ? dotted : `${dotted}/${data.prefix}`;\n}\n\nfunction formatSplit(data: SplitData, locale: ILocale, settings: FormattingSettings): string {\n const prefix = locale.display.resultPrefix;\n const render = (share: SplitShare): string => {\n const v = data.unit !== undefined\n ? new Value(ValueType.Uom, share.value, data.unit)\n : new Value(ValueType.Number, share.value);\n v.exact = share.exact;\n const text = formatValue(v, settings);\n return text.startsWith(prefix) ? text.slice(prefix.length) : text;\n };\n\n const [base, high] = data.shares;\n const each = `${render(base)} each`;\n if (high === undefined) return `${prefix}${each}`;\n const shareWord = high.count === 1 ? \"share\" : \"shares\";\n return `${prefix}${each}, with ${high.count} ${shareWord} paying ${render(high)}`;\n}\n\n/**\n * Render an evaluated {@link Value} as a display string, dispatching on\n * `value.type` to the type-specific formatter (number, hex, datetime, unit\n * of measurement, matrix, range, percentage, ...).\n *\n * Most branches produce a `\"= \"`-prefixed result string (matching the\n * plugin's inline-result convention); `ValueType.Error` is the one\n * exception, it returns the human-readable error message directly\n * (stored in `value.unit`), not an `\"= \"`-prefixed string.\n *\n * @param value - The evaluated value to format.\n * @param settings - Locale/precision/separator options; defaults to\n * {@link DEFAULT_FORMATTING_SETTINGS} when omitted.\n * @example\n * ```typescript\n * const value = engine.evaluateExpression(\"10 USD to GBP\");\n * formatValue(value); // \"= £7.85\" (exact output depends on live exchange rates)\n * ```\n */\nexport function formatValue(value: Value, settings?: FormattingSettings): string {\n const us = settings || DEFAULT_FORMATTING_SETTINGS;\n const localeCode = us.numberResult.decimalSeparatorLocale || \"en\";\n const locale = getLocale(localeCode);\n\n switch (value.type) {\n case ValueType.Number:\n // A measurement with a tolerance renders as \"center ± spread\"; every\n // other number is unchanged, so a plain value is byte-for-byte what it was.\n if (value.uncertainty !== undefined) {\n return formatUncertain(value.value as number, value.uncertainty, locale, us);\n }\n return formatNumber(value.value as number, locale, us, value.decimalPlaces);\n case ValueType.Hex:\n return formatHex(value.value as number | bigint, us, value.unit);\n case ValueType.BigInt:\n return formatBigInt(value.value as bigint);\n case ValueType.String:\n return formatString(value.value as string);\n case ValueType.Boolean:\n return formatBoolean(value.value as boolean);\n case ValueType.Datetime:\n return formatDatetime(value.value as number, locale, us, value.zone);\n case ValueType.Uom:\n return formatUom(value.value as number, value.unit, locale, us, value.exact);\n case ValueType.Matrix:\n return formatMatrix(value.value as MatrixData, locale, us);\n case ValueType.Range: {\n const r = value.value as RangeData;\n return formatRange(r.min, r.max, locale);\n }\n case ValueType.Colour:\n return `${locale.display.resultPrefix}${formatColour(value.value as ColourData)}`;\n case ValueType.Split:\n return formatSplit(value.value as SplitData, locale, us);\n case ValueType.Chart:\n // A chart is drawn from its data by the host; the text answer is its label\n // (`sin(x) over [0, 6.28]`, or the series a sparkline came from).\n return `${locale.display.resultPrefix}${(value.value as ChartData).label}`;\n case ValueType.IpCidr:\n return `${locale.display.resultPrefix}${formatIpCidr(value.value as IpCidrData)}`;\n case ValueType.Symbolic:\n return formatSymbolic(value.value as SymbolicNode);\n case ValueType.Percentage:\n return formatPercentage(value.value as number, locale, us);\n case ValueType.Unit:\n return formatUnit(value.value as number, value.unit);\n case ValueType.Error:\n // errorValue(code, message) stores the human-readable message in\n // `.unit` (code goes in `.value`), falling through to the default\n // case here previously displayed the raw code (e.g.\n // \"CURRENCY_RATE_UNAVAILABLE\") instead of the actual message.\n return value.unit ?? String(value.value);\n default:\n return `= ${String(value.value)}`;\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk5IJD5L3O_cjs=require('./chunk-5IJD5L3O.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunkYBQPEWT7_cjs=require('./chunk-YBQPEWT7.cjs');var o={Lowest:0,Assignment:10,LogicalOr:12,LogicalAnd:14,Conjunction:16,BitwiseOr:18,BitwiseXor:20,BitwiseAnd:22,Conditional:24,Shift:27,Sum:30,Product:40,Uncertainty:45,Exponent:50,Prefix:60,Postfix:70,Call:80};var f={[chunk5IJD5L3O_cjs.a.PLUS]:o.Sum,[chunk5IJD5L3O_cjs.a.MINUS]:o.Sum,[chunk5IJD5L3O_cjs.a.STAR]:o.Product,[chunk5IJD5L3O_cjs.a.SLASH]:o.Product,[chunk5IJD5L3O_cjs.a.MOD]:o.Product,[chunk5IJD5L3O_cjs.a.CARET]:o.Exponent,[chunk5IJD5L3O_cjs.a.BIT_OR]:o.BitwiseOr,[chunk5IJD5L3O_cjs.a.BIT_XOR]:o.BitwiseXor,[chunk5IJD5L3O_cjs.a.BIT_AND]:o.BitwiseAnd,[chunk5IJD5L3O_cjs.a.LSHIFT]:o.Shift,[chunk5IJD5L3O_cjs.a.RSHIFT]:o.Shift,[chunk5IJD5L3O_cjs.a.URSHIFT]:o.Shift,[chunk5IJD5L3O_cjs.a.PERCENT]:o.Postfix,[chunk5IJD5L3O_cjs.a.OF]:o.Product},h=null;function F(){if(h)return h;let i=0;for(let n of Object.keys(f)){let t=chunk5IJD5L3O_cjs.c(n);t>i&&(i=t);}for(let n of Object.values(chunk5IJD5L3O_cjs.a)){let t=chunk5IJD5L3O_cjs.c(n);t>i&&(i=t);}let e=new Uint8Array(i+1);for(let[n,t]of Object.entries(f)){let u=chunk5IJD5L3O_cjs.c(n);e[u]=t;}return h=e,e}function P(){h=null;}var r=255,A="-0";function m(i,e){if(!Number.isInteger(i)||i<0||i>255)throw chunkYBQPEWT7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`A bytecode ${e} must be an integer from 0 to 255, but ${i} was emitted; the opcode stream stores one byte per operand.`,{value:i,what:e});return i}var O=Object.freeze([]),B=new Float64Array(0),b=class{constructor(e){this.pluginFunctionIndex=e;this.opcodes=[];this.numbers=[];this.strings=[];this.stringIndex=new Map;this.numberIndex=new Map;this._hasAsync=false;this.userFunctionBodies=[];this.anonymousBodies=[];}get pluginIndexMap(){return this.pluginFunctionIndex}emitPluginCall(e,n){let t=this.pluginFunctionIndex?.get(e);if(t===void 0)throw chunkYBQPEWT7_cjs.c.execution("UNKNOWN_PLUGIN_FUNCTION",`No registered plugin function named "${e}". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,{functionName:e});if(t>65535)throw chunkYBQPEWT7_cjs.c.parsing("PLUGIN_FUNCTION_INDEX_TOO_LARGE",`Plugin-function index ${t} exceeds the two-byte bytecode limit (65535).`,{index:t});t<=255?(this.emitOpcode(50),this.emitIndex(t)):(this.emitOpcode(161),this.emitIndex(t&255),this.emitIndex(t>>8&255)),this.emitIndex(n);}emitOpcode(e){this.opcodes.push(e),(e===50||e===161)&&(this._hasAsync=true);}emitNumber(e){let n=Object.is(e,-0)?A:e,t=this.numberIndex.get(n);if(t===void 0){if(t=this.numbers.length,t>r)throw chunkYBQPEWT7_cjs.c.parsing("TOO_MANY_NUMERIC_CONSTANTS",`Expression has more than ${r+1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.numbers.push(e),this.numberIndex.set(n,t);}this.opcodes.push(t);}emitString(e){let n=this.stringIndex.get(e);if(n===void 0){if(n=this.strings.length,n>r)throw chunkYBQPEWT7_cjs.c.parsing("TOO_MANY_STRING_CONSTANTS",`Expression has more than ${r+1} distinct string literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.strings.push(e),this.stringIndex.set(e,n);}this.opcodes.push(n);}emitIndex(e){this.opcodes.push(m(e,"index"));}emitByte(e){this.opcodes.push(m(e,"byte"));}get currentLength(){return this.opcodes.length}emitUserFunctionBody(e,n,t){let u=this.userFunctionBodies.length;if(u>r)throw chunkYBQPEWT7_cjs.c.parsing("TOO_MANY_FUNCTION_DEFINITIONS",`More than ${r+1} function definitions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.userFunctionBodies.push({name:e,params:n,program:t}),u}emitAnonymousBody(e,n){let t=this.anonymousBodies.length;if(t>r)throw chunkYBQPEWT7_cjs.c.parsing("TOO_MANY_ANONYMOUS_BODIES",`More than ${r+1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.anonymousBodies.push({params:e,program:n}),t}patchJump(e,n){if(e<0||e>=this.opcodes.length)throw chunkYBQPEWT7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`patchJump was asked to write at position ${e}, outside the ${this.opcodes.length} bytes emitted so far.`,{position:e,length:this.opcodes.length});this.opcodes[e]=m(n,"jump target");}build(){return {opcodes:new Uint8Array(this.opcodes),numbers:this.numbers.length>0?new Float64Array(this.numbers):B,strings:this.strings.length>0?[...this.strings]:O,hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}buildInto(e){let n=this.opcodes.length,t=this.numbers.length,u=e&&e.opcodes.length>=n,I=e&&e.numbers.length>=t,g=u?new Uint8Array(e.opcodes.buffer,e.opcodes.byteOffset,n):new Uint8Array(n),p=I?new Float64Array(e.numbers.buffer,e.numbers.byteOffset,t):new Float64Array(t);for(let c=0;c<n;c++)g[c]=this.opcodes[c];for(let c=0;c<t;c++)p[c]=this.numbers[c];return {opcodes:g,numbers:p,strings:[...this.strings],hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}reset(){this.opcodes.length=0,this.numbers.length>0&&(this.numbers.length=0,this.numberIndex.clear()),this.strings.length>0&&(this.strings.length=0,this.stringIndex.clear()),this._hasAsync=false,this.userFunctionBodies.length>0&&(this.userFunctionBodies.length=0),this.anonymousBodies.length>0&&(this.anonymousBodies.length=0);}};var _=/^\d{1,3}(\.\d{3}){2,}$/,y=/^\d+$/;function R(i,e){let n=i.endsWith("n")?i.slice(0,-1):i;if(y.test(n))return n;let t=_.test(n)?n.split(".").join(""):x(n,e);if(!y.test(t)){let u=n.includes(".")?".":n.includes(",")?",":n;throw chunkYBQPEWT7_cjs.c.parsing("INVALID_NUMBER_LITERAL",`"${i}" is not a whole number: "${u}" separates decimals in the ${e} locale, and a whole number cannot have a fractional part.`,{raw:i,localeCode:e,separator:u})}return t}function x(i,e){let n=chunkS3DFU33X_cjs.a(e).display.thousandsSeparator;return n?i.split(n).join(""):i}exports.a=o;exports.b=F;exports.c=P;exports.d=b;exports.e=R;//# sourceMappingURL=chunk-FYTB7SDP.cjs.map
2
- //# sourceMappingURL=chunk-FYTB7SDP.cjs.map
1
+ 'use strict';var chunkYBQOQTVL_cjs=require('./chunk-YBQOQTVL.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunkGXO7TSXQ_cjs=require('./chunk-GXO7TSXQ.cjs');var o={Lowest:0,Assignment:10,LogicalOr:12,LogicalAnd:14,Conjunction:16,BitwiseOr:18,BitwiseXor:20,BitwiseAnd:22,Conditional:24,Shift:27,Sum:30,Product:40,Uncertainty:45,Exponent:50,Prefix:60,Postfix:70,Call:80};var f={[chunkYBQOQTVL_cjs.a.PLUS]:o.Sum,[chunkYBQOQTVL_cjs.a.MINUS]:o.Sum,[chunkYBQOQTVL_cjs.a.STAR]:o.Product,[chunkYBQOQTVL_cjs.a.SLASH]:o.Product,[chunkYBQOQTVL_cjs.a.MOD]:o.Product,[chunkYBQOQTVL_cjs.a.CARET]:o.Exponent,[chunkYBQOQTVL_cjs.a.BIT_OR]:o.BitwiseOr,[chunkYBQOQTVL_cjs.a.BIT_XOR]:o.BitwiseXor,[chunkYBQOQTVL_cjs.a.BIT_AND]:o.BitwiseAnd,[chunkYBQOQTVL_cjs.a.LSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.RSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.URSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.PERCENT]:o.Postfix,[chunkYBQOQTVL_cjs.a.OF]:o.Product},h=null;function F(){if(h)return h;let i=0;for(let n of Object.keys(f)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}for(let n of Object.values(chunkYBQOQTVL_cjs.a)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}let e=new Uint8Array(i+1);for(let[n,t]of Object.entries(f)){let u=chunkYBQOQTVL_cjs.c(n);e[u]=t;}return h=e,e}function P(){h=null;}var r=255,A="-0";function m(i,e){if(!Number.isInteger(i)||i<0||i>255)throw chunkGXO7TSXQ_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`A bytecode ${e} must be an integer from 0 to 255, but ${i} was emitted; the opcode stream stores one byte per operand.`,{value:i,what:e});return i}var O=Object.freeze([]),B=new Float64Array(0),b=class{constructor(e){this.pluginFunctionIndex=e;this.opcodes=[];this.numbers=[];this.strings=[];this.stringIndex=new Map;this.numberIndex=new Map;this._hasAsync=false;this.userFunctionBodies=[];this.anonymousBodies=[];}get pluginIndexMap(){return this.pluginFunctionIndex}emitPluginCall(e,n){let t=this.pluginFunctionIndex?.get(e);if(t===void 0)throw chunkGXO7TSXQ_cjs.c.execution("UNKNOWN_PLUGIN_FUNCTION",`No registered plugin function named "${e}". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,{functionName:e});if(t>65535)throw chunkGXO7TSXQ_cjs.c.parsing("PLUGIN_FUNCTION_INDEX_TOO_LARGE",`Plugin-function index ${t} exceeds the two-byte bytecode limit (65535).`,{index:t});t<=255?(this.emitOpcode(50),this.emitIndex(t)):(this.emitOpcode(161),this.emitIndex(t&255),this.emitIndex(t>>8&255)),this.emitIndex(n);}emitOpcode(e){this.opcodes.push(e),(e===50||e===161)&&(this._hasAsync=true);}emitNumber(e){let n=Object.is(e,-0)?A:e,t=this.numberIndex.get(n);if(t===void 0){if(t=this.numbers.length,t>r)throw chunkGXO7TSXQ_cjs.c.parsing("TOO_MANY_NUMERIC_CONSTANTS",`Expression has more than ${r+1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.numbers.push(e),this.numberIndex.set(n,t);}this.opcodes.push(t);}emitString(e){let n=this.stringIndex.get(e);if(n===void 0){if(n=this.strings.length,n>r)throw chunkGXO7TSXQ_cjs.c.parsing("TOO_MANY_STRING_CONSTANTS",`Expression has more than ${r+1} distinct string literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.strings.push(e),this.stringIndex.set(e,n);}this.opcodes.push(n);}emitIndex(e){this.opcodes.push(m(e,"index"));}emitByte(e){this.opcodes.push(m(e,"byte"));}get currentLength(){return this.opcodes.length}emitUserFunctionBody(e,n,t){let u=this.userFunctionBodies.length;if(u>r)throw chunkGXO7TSXQ_cjs.c.parsing("TOO_MANY_FUNCTION_DEFINITIONS",`More than ${r+1} function definitions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.userFunctionBodies.push({name:e,params:n,program:t}),u}emitAnonymousBody(e,n){let t=this.anonymousBodies.length;if(t>r)throw chunkGXO7TSXQ_cjs.c.parsing("TOO_MANY_ANONYMOUS_BODIES",`More than ${r+1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.anonymousBodies.push({params:e,program:n}),t}patchJump(e,n){if(e<0||e>=this.opcodes.length)throw chunkGXO7TSXQ_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`patchJump was asked to write at position ${e}, outside the ${this.opcodes.length} bytes emitted so far.`,{position:e,length:this.opcodes.length});this.opcodes[e]=m(n,"jump target");}build(){return {opcodes:new Uint8Array(this.opcodes),numbers:this.numbers.length>0?new Float64Array(this.numbers):B,strings:this.strings.length>0?[...this.strings]:O,hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}buildInto(e){let n=this.opcodes.length,t=this.numbers.length,u=e&&e.opcodes.length>=n,I=e&&e.numbers.length>=t,g=u?new Uint8Array(e.opcodes.buffer,e.opcodes.byteOffset,n):new Uint8Array(n),p=I?new Float64Array(e.numbers.buffer,e.numbers.byteOffset,t):new Float64Array(t);for(let c=0;c<n;c++)g[c]=this.opcodes[c];for(let c=0;c<t;c++)p[c]=this.numbers[c];return {opcodes:g,numbers:p,strings:[...this.strings],hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}reset(){this.opcodes.length=0,this.numbers.length>0&&(this.numbers.length=0,this.numberIndex.clear()),this.strings.length>0&&(this.strings.length=0,this.stringIndex.clear()),this._hasAsync=false,this.userFunctionBodies.length>0&&(this.userFunctionBodies.length=0),this.anonymousBodies.length>0&&(this.anonymousBodies.length=0);}};var _=/^\d{1,3}(\.\d{3}){2,}$/,y=/^\d+$/;function R(i,e){let n=i.endsWith("n")?i.slice(0,-1):i;if(y.test(n))return n;let t=_.test(n)?n.split(".").join(""):x(n,e);if(!y.test(t)){let u=n.includes(".")?".":n.includes(",")?",":n;throw chunkGXO7TSXQ_cjs.c.parsing("INVALID_NUMBER_LITERAL",`"${i}" is not a whole number: "${u}" separates decimals in the ${e} locale, and a whole number cannot have a fractional part.`,{raw:i,localeCode:e,separator:u})}return t}function x(i,e){let n=chunkS3DFU33X_cjs.a(e).display.thousandsSeparator;return n?i.split(n).join(""):i}exports.a=o;exports.b=F;exports.c=P;exports.d=b;exports.e=R;//# sourceMappingURL=chunk-ZDJTDFTR.cjs.map
2
+ //# sourceMappingURL=chunk-ZDJTDFTR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/BindingPower.ts","../src/parser/BytecodeBuilder.ts","../src/parser/BigIntLiteral.ts"],"names":["BindingPower","BUILTIN_INFIX_BP","TokenTypes","_bpTable","buildBindingPowerTable","maxId","name","id","tokenTypeId","table","bp","invalidateBindingPowerTable","MAX_CONSTANT_POOL_INDEX","NEGATIVE_ZERO_KEY","checkedOperand","value","what","ErrorFactory","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","op","n","key","idx","s","b","params","program","position","target","buf","opLen","numLen","reuseOpcodes","reuseNumbers","opcodes","numbers","i","CHAINED_DOT_THOUSANDS_GROUPS","DIGITS_ONLY","bigIntLiteralDigits","raw","localeCode","withoutSuffix","digits","stripLocaleGrouping","separator","text","thousandsSeparator","getLocale"],"mappings":"uKAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,UAAA,CAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,EAAA,CAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,WAAA,CAAa,EAAA,CACb,KAAA,CAAO,EAAA,CACP,GAAA,CAAK,EAAA,CACL,OAAA,CAAS,EAAA,CAMT,WAAA,CAAa,EAAA,CAIb,QAAA,CAAU,GACV,MAAA,CAAQ,EAAA,CACR,OAAA,CAAS,EAAA,CACT,IAAA,CAAM,EACR,EAiDO,IAAMC,CAAAA,CAA2C,CAEtD,CAACC,mBAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,GAAA,CACpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,GAAA,CACpC,CAACE,mBAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,OAAA,CACpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,OAAA,CACpC,CAACE,mBAAAA,CAAW,GAAG,EAAQF,CAAAA,CAAa,OAAA,CAGpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,QAAA,CAOpC,CAACE,mBAAAA,CAAW,MAAM,EAAKF,CAAAA,CAAa,SAAA,CACpC,CAACE,mBAAAA,CAAW,OAAO,EAAIF,CAAAA,CAAa,UAAA,CACpC,CAACE,mBAAAA,CAAW,OAAO,EAAIF,CAAAA,CAAa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AAAA,CAAoBE,CAAAA,CAAcL,CAAAA,CAA4B,CACtE,IAAMM,CAAAA,CAAqBC,mBAAAA,CAAUP,CAAU,CAAA,CAAE,OAAA,CAAQ,kBAAA,CACzD,OAAOM,CAAAA,CAAqBD,CAAAA,CAAK,KAAA,CAAMC,CAAkB,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAAID,CACvE","file":"chunk-FYTB7SDP.cjs","sourcesContent":["/**\n * Named precedence levels for the Pratt parser, from loosest (`Lowest`) to\n * tightest (`Call`) binding. A custom infix parselet compares its own\n * binding power against the current expression's to decide whether to\n * consume the next operator (higher power binds tighter, e.g. `*` over `+`).\n *\n * Package authors reference these when declaring an infix parselet in a\n * package's `infixParselets`. See the built-in packages for examples of\n * picking an appropriate level (e.g. arithmetic `+`/`-` use `Sum`, `*`/`/`\n * use `Product`).\n */\nexport const BindingPower = {\n Lowest: 0,\n Assignment: 10,\n LogicalOr: 12, // `or`, `||` — loosest of the boolean-logic operators\n LogicalAnd: 14, // `&&` — binds tighter than `or` (\"a or b and c\" = \"a or (b and c)\")\n // The word \"and\" (`AND_CONJ`), which is both arithmetic addition (\"5 and 3\"\n // is 8) and boolean conjunction (\"true and false\"). A phrase parselet\n // collecting a list (\"average of X, Y and Z\") parses each argument at this\n // level, and an argument stops at any operator whose power is <= the level it\n // was parsed at, so putting \"and\" here is what makes it end an argument\n // rather than be consumed as the addition it also is. Everything an argument\n // should keep binds tighter, including a genuine \"+\" (`Sum`).\n //\n // It sits BELOW `Conditional` because the boolean reading needs comparisons\n // to be its operands: at 28, \"5 > 3 and 2 > 1\" parsed as \"5 > (3 and 2) > 1\"\n // and answered false. Above `LogicalAnd` so that \"and\" is still the tighter\n // of the two conjunctions, and two steps off each neighbour to leave room.\n Conjunction: 16,\n // The bitwise trio and the shifts, ordered exactly as C and JavaScript order\n // them, which is the order every language that borrowed these operators from\n // C uses: `|` looser than `xor`, `xor` looser than `&`, all three looser than\n // comparison, and the shifts tighter than comparison but looser than `+`.\n // They used to share one level (35) between `Sum` and `Product`, so\n // \"1 + 2 << 3\" answered 17 where JavaScript answers 24 and \"4 & 3 + 1\"\n // answered 1 where JavaScript answers 4. Each has its own level now because\n // a shared level makes \"4 | 6 & 3\" group left instead of letting `&` win.\n //\n // They stay TIGHTER than `Conjunction` so that a phrase argument parsed at\n // that level (\"average of 5 | 3, 2 and 4\") keeps its bitwise operators\n // instead of stopping at the first one.\n BitwiseOr: 18, // `|`\n BitwiseXor: 20, // the `xor` keyword (`BIT_XOR`), not the `^` exponent token\n BitwiseAnd: 22, // `&`\n Conditional: 24, // comparisons (`==`, `<`, `>=`, ...), tighter than the bitwise trio, looser than the shifts\n Shift: 27, // `<<`, `>>`, `>>>`\n Sum: 30,\n Product: 40,\n // `±` (the uncertainty operator), tighter than `+ - * /` and looser than `^`,\n // so the tolerance attaches to its adjacent values: `12.3 ± 0.5 * 4` reads as\n // `(12.3 ± 0.5) * 4` (the parenthesised headline case), and `2 + 3 ± 0.5` as\n // `2 + (3 ± 0.5)`. A Tier-2 parselet (packages/uncertainty/), so this level is\n // read off the parselet rather than the Tier-1 BUILTIN_INFIX_BP table below.\n Uncertainty: 45,\n // `^`, RIGHT-associative: \"2 ^ 3 ^ 2\" is 2^(3^2) = 512, as in mathematics,\n // Python, Ruby and JavaScript's `**`. See PrecedenceParser.parseExpression\n // and BinaryOpParselet for the two places that associativity is implemented.\n Exponent: 50,\n Prefix: 60,\n Postfix: 70,\n Call: 80,\n} as const;\n\n/**\n * Set the binding power of a named operator.\n *\n * Binding power is what decides precedence in the Pratt parser: a higher number\n * binds tighter, so `*` outranks `+`. Changing one changes how every existing\n * expression using that operator parses, which is why packages should allocate\n * a new name rather than adjust a built-in.\n *\n * @param name - Operator name.\n * @param power - Higher binds tighter.\n */\nexport function setBindingPower(name: string, power: number): void {\n (BindingPower as Record<string, number>)[name] = power;\n}\n\n/**\n * Read the binding power of a named operator.\n *\n * @param name - Operator name.\n * @returns Its binding power, or 0 when the name is unknown, which makes an\n * unregistered operator terminate an expression rather than swallow the rest\n * of it.\n */\nexport function getBindingPower(name: string): number {\n return (BindingPower as Record<string, number>)[name] ?? 0;\n}\n\n// ── Built-in Infix Operator Binding Power Table ──────────────────────────────\n// Pre-computed Uint8Array lookup indexed by token typeId.\n// value > 0 → built-in infix operator with that binding power\n// value = 0 → not a built-in infix, fall through to Tier 2 parselet registry\n//\n// Built at module load via buildBindingPowerTable(). The table is sparse\n// most entries are 0 since only ~15 of 80+ token types are infix operators.\n//\n// Performance: Uint8Array[typeId] is a single typed array load, no Map.get()\n// no string hashing, no property chain. V8 eliminates bounds checks when typeId\n// is known to be within array length.\n\nimport { TokenTypes } from \"@solve-js/lexer/Token\";\nimport { tokenTypeId } from \"@solve-js/lexer/Token\";\n\n/**\n * Mapping of token type names → binding powers for built-in infix operators.\n * Only operators listed here get the Tier 1 fast path in PrecedenceParser.\n * All other infix tokens use the Tier 2 parselet registry fallback.\n */\nexport const BUILTIN_INFIX_BP: Record<string, number> = {\n // Arithmetic (infix, left-associative)\n [TokenTypes.PLUS]: BindingPower.Sum,\n [TokenTypes.MINUS]: BindingPower.Sum,\n [TokenTypes.STAR]: BindingPower.Product,\n [TokenTypes.SLASH]: BindingPower.Product,\n [TokenTypes.MOD]: BindingPower.Product,\n\n // Arithmetic (infix, RIGHT-associative, PrecedenceParser handles this specially)\n [TokenTypes.CARET]: BindingPower.Exponent,\n\n // Bitwise and shift (infix, left-associative), one level each, ordered as C\n // and JavaScript order them. `>>>` used to be missing from this table\n // entirely, which left it running at its Tier 2 parselet level while `>>`\n // ran at the Tier 1 one, so \"16 >> 3 & 1\" and \"16 >>> 3 & 1\" grouped\n // differently and answered 0 and 8.\n [TokenTypes.BIT_OR]: BindingPower.BitwiseOr,\n [TokenTypes.BIT_XOR]: BindingPower.BitwiseXor,\n [TokenTypes.BIT_AND]: BindingPower.BitwiseAnd,\n [TokenTypes.LSHIFT]: BindingPower.Shift,\n [TokenTypes.RSHIFT]: BindingPower.Shift,\n [TokenTypes.URSHIFT]: BindingPower.Shift,\n\n // Postfix (no right operand, PrecedenceParser handles this specially)\n [TokenTypes.PERCENT]: BindingPower.Postfix,\n\n // Percentage keyword (infix, left-associative: \"50% of 200\" → MUL)\n [TokenTypes.OF]: BindingPower.Product,\n};\n\n// Note: These token types are intentionally NOT in the BP_TABLE, they stay in\n// the Tier 2 parselet registry because they require complex handling:\n// IN, TO → UoM conversion parselets (peek at target unit token, complex logic)\n// DOT → Property access (chained OBJ_GET, needs left-token tracking)\n// EQUALS → Assignment (VariableParselet handles :var = expr pattern)\n// EQUALITY, NEQ, GTE, LTE → Comparison ops (need dedicated VM opcodes, task 2.15a)\n// COMMA → Argument separator (function calls, array/object literals)\n\n/** Cached BP_TABLE, built once at module load, immutable thereafter. */\nlet _bpTable: Uint8Array | null = null;\n\n/**\n * Build the Uint8Array binding power table indexed by token typeId.\n * Idempotent, returns cached table on subsequent calls.\n *\n * Must be called after all token types are registered (via registerAllTokenTypes())\n * and after plugin providers have registered their token types.\n */\nexport function buildBindingPowerTable(): Uint8Array {\n if (_bpTable) return _bpTable;\n\n // Size to the largest registered typeId + 1\n let maxId = 0;\n for (const name of Object.keys(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n // Also scan all TokenTypes to ensure table covers all registered IDs\n for (const name of Object.values(TokenTypes)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n\n const table = new Uint8Array(maxId + 1);\n for (const [name, bp] of Object.entries(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n table[id] = bp;\n }\n\n _bpTable = table;\n return table;\n}\n\n/**\n * Drop the cached table, so the next {@link buildBindingPowerTable} call builds\n * a fresh one sized to the token types registered by then.\n *\n * It does NOT add a plugin's operator to the Tier 1 fast path, which is what\n * this comment used to promise. The values in the table come from\n * `BUILTIN_INFIX_BP`, which is module-private and has no registration path, so\n * a rebuilt table holds the same binding powers and a plugin token still reads\n * 0. `PrecedenceParser.BP_TABLE` is a static initialized once at class\n * definition time and never re-read, so it would not see a rebuild anyway.\n *\n * A plugin's infix operator takes the Tier 2 parselet-registry route instead,\n * which is where an operator whose binding power the engine does not already\n * know is meant to live.\n */\nexport function invalidateBindingPowerTable(): void {\n _bpTable = null;\n}\n","import { OpCode } from \"@solve-js/parser/OpCode\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * `BytecodeProgram.opcodes` is a `Uint8Array`, every operand written into\n * it (including constant-pool indices from {@link BytecodeBuilder.emitNumber}/\n * {@link BytecodeBuilder.emitString}) is truncated to a single byte on\n * `build()`. Exceeding this silently wraps the index (e.g. entry 300 reads\n * back as entry 44), producing a wrong result with no error. See\n * {@link BytecodeBuilder.emitNumber} for the guard that turns this into a\n * thrown error instead.\n */\nconst MAX_CONSTANT_POOL_INDEX = 255;\n\n/** The `numberIndex` key for negative zero, which `Map` would otherwise fold into positive zero. */\nconst NEGATIVE_ZERO_KEY = \"-0\";\n\n/**\n * An operand that fits the byte the opcode stream stores it in, or a\n * structured refusal. `build()` copies the stream into a `Uint8Array`, which\n * keeps the low eight bits of whatever it is given: an operand of 300 used to\n * become 44 with no error, and the program then read a different constant,\n * plugin function or argument count from the one the parselet emitted. Every\n * raw operand goes through here, so a package author's mistake is reported at\n * compile time as a fault in the package rather than answered with a wrong\n * number.\n */\nfunction checkedOperand(value: number, what: string): number {\n\tif (!Number.isInteger(value) || value < 0 || value > 255) {\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t`A bytecode ${what} must be an integer from 0 to 255, but ${value} was emitted; the opcode stream stores one byte per operand.`,\n\t\t\t{ value, what }\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * Compiled bytecode program produced by {@link BytecodeBuilder}.\n * Ready for consumption by {@link executeBytecode} without further processing.\n */\nexport interface BytecodeProgram {\n\topcodes: Uint8Array;\n\tnumbers: Float64Array;\n\tstrings: string[];\n\t/**\n\t * Numeric constants by opcode position, restored from a snapshot.\n\t *\n\t * Nothing in the compile path writes this: numbers are emitted inline into\n\t * {@link numbers} instead. `build()` used to attach an empty Map to every\n\t * program anyway, which was one allocation per compiled expression, around a\n\t * tenth of parse-and-compile time, for a collection that was never read.\n\t * It is left off now, and only {@link EngineSnapshot} sets it when restoring\n\t * a program that carried one; every reader already guards on its absence.\n\t */\n\tconstants?: Map<number, number>;\n\t/**\n\t * Whether the program contains any async opcodes (CALL_PLUGIN, etc.).\n\t * Set during compilation by the BytecodeBuilder. Allows the engine\n\t * to skip the O(n) resolver preflight check in O(1) for purely\n\t * synchronous expressions like `2 + 2`.\n\t */\n\thasAsync: boolean;\n\t/**\n\t * User-defined-function bodies compiled alongside this program (one\n\t * entry per `name(params) = body` definition on this line). See\n\t * {@link BytecodeBuilder.emitUserFunctionBody}. `OpCode.DEFINE_USER_FUNCTION`'s\n\t * operand is an index into this array, resolved at VM-execution time\n\t * (not parse time) so a diagnostic/lookahead parse that never actually\n\t * executes the definition line has no side effect on `vm.userFunctions`.\n\t */\n\tuserFunctionBodies?: UserFunctionDef[];\n\t/**\n\t * Anonymous function bodies compiled alongside this program, one entry\n\t * per `map`/`reduce` inline transform expression (e.g. the `10*x` in\n\t * `map(10*x, [0,1,500])`). See {@link BytecodeBuilder.emitAnonymousBody}.\n\t * Deliberately a SEPARATE side-table from `userFunctionBodies`, not\n\t * routed through `vm.userFunctions` at all: an inline body has no name\n\t * and must never leak into the persistent name-keyed registry the way\n\t * a real `f(x) = ...` definition does.\n\t */\n\tanonymousBodies?: AnonymousBodyDef[];\n}\n\n/**\n * An anonymous transform body for `map`/`reduce`'s inline-expression form\n * (e.g. `10*x` in `map(10*x, [0,1,500])`, or `acc+x` in `reduce(acc+x,\n * [1,2,3])`). Structurally identical to {@link UserFunctionDef} minus the\n * `name`. See `OpCode.MAP_INVOKE`/`REDUCE_INVOKE` and\n * `vm/VM.ts`'s handlers, which build a call frame from `params`/`args`\n * exactly like `CALL_USER_FUNCTION` does, just without ever registering\n * the body in `vm.userFunctions`.\n */\nexport interface AnonymousBodyDef {\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * A user-defined, parameterized, reusable function's compiled form\n * (`f(x) = 2*x + 1`). See `OpCode.DEFINE_USER_FUNCTION`/`CALL_USER_FUNCTION`\n * and `vm/VM.ts`'s `VM.defineUserFunction`/`getUserFunction`.\n *\n * `program` is the body compiled to its OWN independent `BytecodeProgram`,\n * not a fragment of the definition line's own bytecode. Parameter names\n * inside the body compile to ORDINARY `LOAD_VAR <name>` opcodes, no\n * parse-time rewriting, because parameter resolution happens dynamically\n * at the VM level: `CALL_USER_FUNCTION` pushes a name-keyed call frame\n * (`Map<string, Value>`) before re-executing `program`, and `VM.getVar()`\n * checks the innermost call frame before falling back to the flat\n * document-variable store. This is why a `UNIT`-collision parameter name\n * (e.g. `h` in `area(w, h) = w * h`, which lexes as the \"hour\" unit) needs\n * no special handling anywhere, it's just another `LOAD_VAR \"h\"`, resolved\n * the same way as any other name.\n */\nexport interface UserFunctionDef {\n\tname: string;\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * Shared empty collections for programs that emit none.\n *\n * `build()` runs once per compiled expression, so an empty array allocated\n * there is an allocation per line of every document. Most programs emit no\n * strings at all (only the unit and datetime parselets do), and one that emits\n * no numbers is common too, so both were routinely allocating an empty\n * container that nothing would ever read.\n *\n * Sharing them is safe because a built program is read-only downstream: the VM\n * and the snapshot writer only index and iterate these, and nothing in the\n * engine pushes to `program.strings` or `program.numbers`. They are frozen so\n * that a future writer fails loudly here rather than silently corrupting every\n * other program that shares the instance.\n */\nconst EMPTY_STRINGS: readonly string[] = Object.freeze([]);\nconst EMPTY_NUMBERS = new Float64Array(0);\n\n/**\n * Direct-to-bytecode compiler for the Pratt parser.\n *\n * Accumulates opcodes, numeric constants, and string references during parsing,\n * then produces a {@link BytecodeProgram} for VM execution. Supports:\n * - Standard build via {@link build}\n * - Zero-copy build into pre-allocated buffers via {@link buildInto}\n * - In-place reset for reuse without reallocation\n */\nexport class BytecodeBuilder {\n\tprivate opcodes: number[] = [];\n\tprivate numbers: number[] = [];\n\tprivate strings: string[] = [];\n\tprivate stringIndex = new Map<string, number>();\n\t/** Value (or {@link NEGATIVE_ZERO_KEY}) to its slot in `numbers`, so a repeated literal is emitted once. */\n\tprivate numberIndex = new Map<number | string, number>();\n\tprivate _hasAsync = false;\n\tprivate userFunctionBodies: UserFunctionDef[] = [];\n\tprivate anonymousBodies: AnonymousBodyDef[] = [];\n\n\t/**\n\t * The per-engine `plugin function name -> registry index` map, wired in by\n\t * the engine so {@link emitPluginCall} can resolve a name at emit time. The\n\t * same object reference is shared with every builder in an engine (the pool\n\t * and each ad-hoc nested-body builder), and the engine populates it as\n\t * packages register, so a parselet never sees the numeric index.\n\t */\n\tconstructor(private readonly pluginFunctionIndex?: ReadonlyMap<string, number>) {}\n\n\t/** The name->index map, so a nested-body builder inherits the same resolution. */\n\tget pluginIndexMap(): ReadonlyMap<string, number> | undefined {\n\t\treturn this.pluginFunctionIndex;\n\t}\n\n\t/**\n\t * Emit a plugin-function call by NAME. The engine assigns each registered\n\t * `pluginFunctions` entry an index at registration; this resolves the name to\n\t * that index and emits `CALL_PLUGIN` + index + argCount. Package authors emit\n\t * through this rather than a hand-allocated index.\n\t */\n\temitPluginCall(name: string, argCount: number): void {\n\t\tconst index = this.pluginFunctionIndex?.get(name);\n\t\tif (index === undefined) {\n\t\t\tthrow ErrorFactory.execution(\n\t\t\t\t\"UNKNOWN_PLUGIN_FUNCTION\",\n\t\t\t\t`No registered plugin function named \"${name}\". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,\n\t\t\t\t{ functionName: name },\n\t\t\t);\n\t\t}\n\t\t// One byte covers the first 256 plugin functions; beyond that, the\n\t\t// wide opcode carries a two-byte little-endian index. Emitting the\n\t\t// narrow form whenever it fits keeps existing bytecode and snapshots\n\t\t// byte-for-byte unchanged. The index cannot exceed 65535 because the\n\t\t// allocator (allocatePluginFunctionIndex) caps it, but guard anyway so\n\t\t// a stray index is a clear error rather than a silently truncated byte.\n\t\tif (index > 0xffff) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"PLUGIN_FUNCTION_INDEX_TOO_LARGE\",\n\t\t\t\t`Plugin-function index ${index} exceeds the two-byte bytecode limit (65535).`,\n\t\t\t\t{ index },\n\t\t\t);\n\t\t}\n\t\tif (index <= 0xff) {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN);\n\t\t\tthis.emitIndex(index);\n\t\t} else {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN_WIDE);\n\t\t\tthis.emitIndex(index & 0xff); // low byte\n\t\t\tthis.emitIndex((index >> 8) & 0xff); // high byte\n\t\t}\n\t\tthis.emitIndex(argCount);\n\t}\n\n\t/** Emit an {@link OpCode} instruction. */\n\temitOpcode(op: OpCode): void {\n\t\tthis.opcodes.push(op);\n\t\tif (op === OpCode.CALL_PLUGIN || op === OpCode.CALL_PLUGIN_WIDE) {\n\t\t\tthis._hasAsync = true;\n\t\t}\n\t}\n\n\t/**\n\t * Emit a numeric literal: interns `n` into the program's constant pool\n\t * (deduplicated, like {@link emitString}) and writes its index into the\n\t * opcode stream (read back by the VM as e.g. `PUSH_NUMBER <idx>`).\n\t *\n\t * Deduplicated so that the 256-entry pool counts distinct values rather\n\t * than occurrences: a long line of repeated literals used to exhaust it\n\t * long before it held 256 different numbers. Negative zero keeps its own\n\t * slot, because `1 / -0` is not `1 / 0`; NaN shares one, since every NaN\n\t * reads the same.\n\t *\n\t * @throws If the pool would exceed 256 distinct entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst key = Object.is(n, -0) ? NEGATIVE_ZERO_KEY : n;\n\t\tlet idx = this.numberIndex.get(key);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.numbers.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.numbers.push(n);\n\t\t\tthis.numberIndex.set(key, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a string literal: interns `s` into the program's string pool\n\t * (deduplicated via `stringIndex`) and writes its index into the opcode\n\t * stream. Subject to the same constant-pool bound as {@link emitNumber},\n\t * but since strings ARE deduplicated, only distinct string values count\n\t * against the limit.\n\t *\n\t * @throws If the string pool would exceed 256 distinct entries.\n\t */\n\temitString(s: string): void {\n\t\tlet idx = this.stringIndex.get(s);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.strings.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_STRING_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct string literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.strings.push(s);\n\t\t\tthis.stringIndex.set(s, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a raw numeric operand (0-255) following an opcode, e.g. a\n\t * plugin-function index for `CALL_PLUGIN`, or an argument count. Unlike\n\t * {@link emitOpcode}, this does not go through the `OpCode` enum, so\n\t * package authors use this (not an unsafe cast to `OpCode`) to push\n\t * operands their own opcode handler expects to read positionally.\n\t */\n\temitIndex(idx: number): void {\n\t\tthis.opcodes.push(checkedOperand(idx, \"index\"));\n\t}\n\n\t/** Emit a raw byte (0-255), used for fixed small operands like argument counts. */\n\temitByte(b: number): void {\n\t\tthis.opcodes.push(checkedOperand(b, \"byte\"));\n\t}\n\n\t/** Number of opcodes/operands emitted so far, used to compute jump targets before {@link patchJump}. */\n\tget currentLength(): number {\n\t\treturn this.opcodes.length;\n\t}\n\n\t/**\n\t * Register a compiled user-defined-function body, returning its index\n\t * into this program's `userFunctionBodies` side-table, the caller emits\n\t * that index as `DEFINE_USER_FUNCTION`'s operand via {@link emitIndex}.\n\t * Subject to the same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitNumber}/{@link emitString} (the index itself is a single\n\t * opcode-stream byte), in practice a single line defines at most a\n\t * handful of functions, so this limit is never realistically reached.\n\t *\n\t * @throws If more than 256 function bodies are registered on one program.\n\t */\n\temitUserFunctionBody(name: string, params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.userFunctionBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_FUNCTION_DEFINITIONS\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} function definitions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.userFunctionBodies.push({ name, params, program });\n\t\treturn idx;\n\t}\n\n\t/**\n\t * Register a compiled `map`/`reduce` anonymous transform body, returning\n\t * its index into this program's `anonymousBodies` side-table, the\n\t * caller emits that index as `MAP_INVOKE`/`REDUCE_INVOKE`'s operand via\n\t * {@link emitIndex}. Same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitUserFunctionBody}.\n\t *\n\t * @throws If more than 256 anonymous bodies are registered on one program.\n\t */\n\temitAnonymousBody(params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.anonymousBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_ANONYMOUS_BODIES\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.anonymousBodies.push({ params, program });\n\t\treturn idx;\n\t}\n\n\t/** Overwrite a previously-emitted placeholder operand at `position` with the real jump `target`, once known. */\n\tpatchJump(position: number, target: number): void {\n\t\tif (position < 0 || position >= this.opcodes.length) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t\t`patchJump was asked to write at position ${position}, outside the ${this.opcodes.length} bytes emitted so far.`,\n\t\t\t\t{ position, length: this.opcodes.length }\n\t\t\t);\n\t\t}\n\t\tthis.opcodes[position] = checkedOperand(target, \"jump target\");\n\t}\n\n\t/**\n\t * Build the accumulated opcodes/numbers/strings into a BytecodeProgram.\n\t * Creates new TypedArrays, the builder can be reused after this call.\n\t */\n\tbuild(): BytecodeProgram {\n\t\treturn {\n\t\t\topcodes: new Uint8Array(this.opcodes),\n\t\t\tnumbers: this.numbers.length > 0 ? new Float64Array(this.numbers) : EMPTY_NUMBERS,\n\t\t\t// Defensive copy when there is anything to copy: reset()'s\n\t\t\t// `.length = 0` would otherwise clear a reference the program still\n\t\t\t// holds. An empty one needs no copy, so it shares the frozen\n\t\t\t// singleton instead of allocating per program.\n\t\t\tstrings: this.strings.length > 0 ? [...this.strings] : (EMPTY_STRINGS as string[]),\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Build directly into a pre-allocated buffer for zero-copy VM consumption.\n\t *\n\t * When `buf` is provided and large enough, writes into it and returns\n\t * subarray **views** (not copies), the returned TypedArrays share the\n\t * buffer's underlying ArrayBuffer. The caller MUST NOT mutate the buffer\n\t * until the returned BytecodeProgram is no longer needed.\n\t *\n\t * If the caller intends to cache the result, they must copy the TypedArrays\n\t * (e.g. `new Uint8Array(program.opcodes)`) before reusing the buffer pool.\n\t *\n\t * When `buf` is omitted or too small, allocates fresh TypedArrays.\n\t */\n\tbuildInto(buf?: { opcodes: Uint8Array; numbers: Float64Array }): BytecodeProgram {\n\t\tconst opLen = this.opcodes.length;\n\t\tconst numLen = this.numbers.length;\n\n\t\tconst reuseOpcodes = buf && buf.opcodes.length >= opLen;\n\t\tconst reuseNumbers = buf && buf.numbers.length >= numLen;\n\n\t\t// Subarray views that share the buffer's ArrayBuffer (zero-copy)\n\t\tconst opcodes = reuseOpcodes\n\t\t\t? new Uint8Array(buf!.opcodes.buffer, buf!.opcodes.byteOffset, opLen)\n\t\t\t: new Uint8Array(opLen);\n\t\tconst numbers = reuseNumbers\n\t\t\t? new Float64Array(buf!.numbers.buffer, buf!.numbers.byteOffset, numLen)\n\t\t\t: new Float64Array(numLen);\n\n\t\t// Write data into the views\n\t\tfor (let i = 0; i < opLen; i++) opcodes[i] = this.opcodes[i];\n\t\tfor (let i = 0; i < numLen; i++) numbers[i] = this.numbers[i];\n\n\t\treturn {\n\t\t\topcodes,\n\t\t\tnumbers,\n\t\t\tstrings: [...this.strings],\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\treset(): void {\n\t\t// Retain backing stores with .length = 0 to avoid reallocation on growth.\n\t\t// = [] discards the ArrayBuffer, forcing V8 to reallocate on every push()\n\t\t// threshold (4→8→16→32...). For a 50-opcode expression, that's 3-4 copies.\n\t\tthis.opcodes.length = 0;\n\t\tif (this.numbers.length > 0) {\n\t\t\tthis.numbers.length = 0;\n\t\t\tthis.numberIndex.clear();\n\t\t}\n\t\t// Guarded on being non-empty. reset() runs once per compiled expression\n\t\t// and a CPU profile put it at over a tenth of parse-and-compile, which\n\t\t// is a lot for clearing collections that are usually already empty:\n\t\t// most expressions emit no strings, and user function bodies are rarer\n\t\t// still. Emptying an empty Map is not free, and neither is the write\n\t\t// barrier on a length assignment.\n\t\tif (this.strings.length > 0) {\n\t\t\tthis.strings.length = 0;\n\t\t\tthis.stringIndex.clear();\n\t\t}\n\t\tthis._hasAsync = false;\n\t\tif (this.userFunctionBodies.length > 0) this.userFunctionBodies.length = 0;\n\t\tif (this.anonymousBodies.length > 0) this.anonymousBodies.length = 0;\n\t}\n}\n","/**\n * Turning a `123n` literal's source text into the digits `PUSH_BIGINT` stores.\n *\n * The lexer coalesces thousands groups into the number token it is building,\n * accepting both `,` and `.` as the separator regardless of locale (see\n * `lexer/ExpressionLexer.ts`'s \"Thousands separators\" block). For a NUMBER that\n * is fine, because the separators are stripped again when the text is turned\n * into a double. For a BIGINT nothing stripped them: both consumers took the\n * token text, removed the trailing `n`, and handed the rest straight to\n * `BigInt()`.\n *\n * So `1.000n` reached `BigInt(\"1.000\")`, which throws a raw `SyntaxError` that\n * arrived at the host as UNEXPECTED_ERROR/INTERNAL: the engine reporting its\n * own bug for six characters a user typed. `1.01n` and `1.1n` were fine, which\n * is the tell that the `n` suffix was never the problem, the three-digit\n * thousands group was: a dot followed by exactly three digits is what the lexer\n * swallows, and one followed by one or two digits it leaves alone.\n *\n * Written once here rather than inline at both call sites. There are two\n * (`parser/PrecedenceParser.ts`'s Tier-1 switch and\n * `packages/biginteger/parselets/BigIntNumberParselet.ts`), they already held\n * identical copies of the `n`-stripping, and the two tiers disagreeing about a\n * literal is a bug shape this codebase has had before.\n *\n * @module BigIntLiteral\n */\n\nimport { getLocale } from \"@solve-js/constants/locales\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Two or more dot-separated groups of three, e.g. `1.234.567`.\n *\n * Unambiguous in any locale, since no locale writes two decimal points, so this\n * is stripped without consulting one. Same regex and same reasoning as\n * `NumberParselet.ts`'s copy for the NUMBER path.\n */\nconst CHAINED_DOT_THOUSANDS_GROUPS = /^\\d{1,3}(\\.\\d{3}){2,}$/;\n\n/** Digits and nothing else, which is what `BigInt()` can be handed safely. */\nconst DIGITS_ONLY = /^\\d+$/;\n\n/**\n * The digit string behind a bigint literal.\n *\n * A bigint literal has no fractional part by construction: the lexer only emits\n * BIGINT when it saw no decimal point of its own and no exponent, so any `.` or\n * `,` still in the text got there as a thousands group. Which of the two the\n * writer meant is a locale question, and answering it wrongly would silently\n * change the value by three orders of magnitude, so only the separator this\n * locale actually uses for grouping is removed. Anything left over is refused\n * rather than guessed at.\n *\n * @param raw - The token's text, with or without the trailing `n`.\n * @param localeCode - The engine's active locale.\n * @returns A string of digits, ready for `BigInt()`.\n * @throws An `INVALID_NUMBER_LITERAL` parsing error when what is left is not a\n * whole number, e.g. `1.000n` in a locale that writes decimals with a dot.\n */\nexport function bigIntLiteralDigits(raw: string, localeCode: string): string {\n\tconst withoutSuffix = raw.endsWith(\"n\") ? raw.slice(0, -1) : raw;\n\n\t// The common case first: nothing was grouped, so there is nothing to decide.\n\tif (DIGITS_ONLY.test(withoutSuffix)) return withoutSuffix;\n\n\tconst digits = CHAINED_DOT_THOUSANDS_GROUPS.test(withoutSuffix)\n\t\t? withoutSuffix.split(\".\").join(\"\")\n\t\t: stripLocaleGrouping(withoutSuffix, localeCode);\n\n\tif (!DIGITS_ONLY.test(digits)) {\n\t\tconst separator = withoutSuffix.includes(\".\") ? \".\" : withoutSuffix.includes(\",\") ? \",\" : withoutSuffix;\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"INVALID_NUMBER_LITERAL\",\n\t\t\t`\"${raw}\" is not a whole number: \"${separator}\" separates decimals in the ${localeCode} locale, and a whole number cannot have a fractional part.`,\n\t\t\t{ raw, localeCode, separator },\n\t\t);\n\t}\n\treturn digits;\n}\n\n/**\n * Removes the active locale's own thousands separator and nothing else.\n *\n * @param text - The literal without its `n`.\n * @param localeCode - The engine's active locale.\n * @returns The text with grouping removed, which the caller then re-checks.\n */\nfunction stripLocaleGrouping(text: string, localeCode: string): string {\n\tconst thousandsSeparator = getLocale(localeCode).display.thousandsSeparator;\n\treturn thousandsSeparator ? text.split(thousandsSeparator).join(\"\") : text;\n}\n"]}
1
+ {"version":3,"sources":["../src/parser/BindingPower.ts","../src/parser/BytecodeBuilder.ts","../src/parser/BigIntLiteral.ts"],"names":["BindingPower","BUILTIN_INFIX_BP","TokenTypes","_bpTable","buildBindingPowerTable","maxId","name","id","tokenTypeId","table","bp","invalidateBindingPowerTable","MAX_CONSTANT_POOL_INDEX","NEGATIVE_ZERO_KEY","checkedOperand","value","what","ErrorFactory","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","op","n","key","idx","s","b","params","program","position","target","buf","opLen","numLen","reuseOpcodes","reuseNumbers","opcodes","numbers","i","CHAINED_DOT_THOUSANDS_GROUPS","DIGITS_ONLY","bigIntLiteralDigits","raw","localeCode","withoutSuffix","digits","stripLocaleGrouping","separator","text","thousandsSeparator","getLocale"],"mappings":"uKAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,UAAA,CAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,EAAA,CAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,WAAA,CAAa,EAAA,CACb,KAAA,CAAO,EAAA,CACP,GAAA,CAAK,EAAA,CACL,OAAA,CAAS,EAAA,CAMT,WAAA,CAAa,EAAA,CAIb,QAAA,CAAU,GACV,MAAA,CAAQ,EAAA,CACR,OAAA,CAAS,EAAA,CACT,IAAA,CAAM,EACR,EAiDO,IAAMC,CAAAA,CAA2C,CAEtD,CAACC,mBAAA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D,CAAU,CAAA,CAEhD,GAAI,CAACH,CAAAA,CAAY,IAAA,CAAKK,CAAM,CAAA,CAAG,CAC9B,IAAME,CAAAA,CAAYH,CAAAA,CAAc,QAAA,CAAS,GAAG,CAAA,CAAI,GAAA,CAAMA,CAAAA,CAAc,QAAA,CAAS,GAAG,CAAA,CAAI,GAAA,CAAMA,CAAAA,CAC1F,MAAM9B,mBAAAA,CAAa,OAAA,CAClB,wBAAA,CACA,CAAA,CAAA,EAAI4B,CAAG,CAAA,0BAAA,EAA6BK,CAAS,CAAA,4BAAA,EAA+BJ,CAAU,CAAA,0DAAA,CAAA,CACtF,CAAE,GAAA,CAAAD,CAAAA,CAAK,UAAA,CAAAC,CAAAA,CAAY,SAAA,CAAAI,CAAU,CAC9B,CACD,CACA,OAAOF,CACR,CASA,SAASC,CAAAA,CAAoBE,CAAAA,CAAcL,CAAAA,CAA4B,CACtE,IAAMM,CAAAA,CAAqBC,mBAAAA,CAAUP,CAAU,CAAA,CAAE,OAAA,CAAQ,kBAAA,CACzD,OAAOM,CAAAA,CAAqBD,CAAAA,CAAK,KAAA,CAAMC,CAAkB,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAAID,CACvE","file":"chunk-ZDJTDFTR.cjs","sourcesContent":["/**\n * Named precedence levels for the Pratt parser, from loosest (`Lowest`) to\n * tightest (`Call`) binding. A custom infix parselet compares its own\n * binding power against the current expression's to decide whether to\n * consume the next operator (higher power binds tighter, e.g. `*` over `+`).\n *\n * Package authors reference these when declaring an infix parselet in a\n * package's `infixParselets`. See the built-in packages for examples of\n * picking an appropriate level (e.g. arithmetic `+`/`-` use `Sum`, `*`/`/`\n * use `Product`).\n */\nexport const BindingPower = {\n Lowest: 0,\n Assignment: 10,\n LogicalOr: 12, // `or`, `||` — loosest of the boolean-logic operators\n LogicalAnd: 14, // `&&` — binds tighter than `or` (\"a or b and c\" = \"a or (b and c)\")\n // The word \"and\" (`AND_CONJ`), which is both arithmetic addition (\"5 and 3\"\n // is 8) and boolean conjunction (\"true and false\"). A phrase parselet\n // collecting a list (\"average of X, Y and Z\") parses each argument at this\n // level, and an argument stops at any operator whose power is <= the level it\n // was parsed at, so putting \"and\" here is what makes it end an argument\n // rather than be consumed as the addition it also is. Everything an argument\n // should keep binds tighter, including a genuine \"+\" (`Sum`).\n //\n // It sits BELOW `Conditional` because the boolean reading needs comparisons\n // to be its operands: at 28, \"5 > 3 and 2 > 1\" parsed as \"5 > (3 and 2) > 1\"\n // and answered false. Above `LogicalAnd` so that \"and\" is still the tighter\n // of the two conjunctions, and two steps off each neighbour to leave room.\n Conjunction: 16,\n // The bitwise trio and the shifts, ordered exactly as C and JavaScript order\n // them, which is the order every language that borrowed these operators from\n // C uses: `|` looser than `xor`, `xor` looser than `&`, all three looser than\n // comparison, and the shifts tighter than comparison but looser than `+`.\n // They used to share one level (35) between `Sum` and `Product`, so\n // \"1 + 2 << 3\" answered 17 where JavaScript answers 24 and \"4 & 3 + 1\"\n // answered 1 where JavaScript answers 4. Each has its own level now because\n // a shared level makes \"4 | 6 & 3\" group left instead of letting `&` win.\n //\n // They stay TIGHTER than `Conjunction` so that a phrase argument parsed at\n // that level (\"average of 5 | 3, 2 and 4\") keeps its bitwise operators\n // instead of stopping at the first one.\n BitwiseOr: 18, // `|`\n BitwiseXor: 20, // the `xor` keyword (`BIT_XOR`), not the `^` exponent token\n BitwiseAnd: 22, // `&`\n Conditional: 24, // comparisons (`==`, `<`, `>=`, ...), tighter than the bitwise trio, looser than the shifts\n Shift: 27, // `<<`, `>>`, `>>>`\n Sum: 30,\n Product: 40,\n // `±` (the uncertainty operator), tighter than `+ - * /` and looser than `^`,\n // so the tolerance attaches to its adjacent values: `12.3 ± 0.5 * 4` reads as\n // `(12.3 ± 0.5) * 4` (the parenthesised headline case), and `2 + 3 ± 0.5` as\n // `2 + (3 ± 0.5)`. A Tier-2 parselet (packages/uncertainty/), so this level is\n // read off the parselet rather than the Tier-1 BUILTIN_INFIX_BP table below.\n Uncertainty: 45,\n // `^`, RIGHT-associative: \"2 ^ 3 ^ 2\" is 2^(3^2) = 512, as in mathematics,\n // Python, Ruby and JavaScript's `**`. See PrecedenceParser.parseExpression\n // and BinaryOpParselet for the two places that associativity is implemented.\n Exponent: 50,\n Prefix: 60,\n Postfix: 70,\n Call: 80,\n} as const;\n\n/**\n * Set the binding power of a named operator.\n *\n * Binding power is what decides precedence in the Pratt parser: a higher number\n * binds tighter, so `*` outranks `+`. Changing one changes how every existing\n * expression using that operator parses, which is why packages should allocate\n * a new name rather than adjust a built-in.\n *\n * @param name - Operator name.\n * @param power - Higher binds tighter.\n */\nexport function setBindingPower(name: string, power: number): void {\n (BindingPower as Record<string, number>)[name] = power;\n}\n\n/**\n * Read the binding power of a named operator.\n *\n * @param name - Operator name.\n * @returns Its binding power, or 0 when the name is unknown, which makes an\n * unregistered operator terminate an expression rather than swallow the rest\n * of it.\n */\nexport function getBindingPower(name: string): number {\n return (BindingPower as Record<string, number>)[name] ?? 0;\n}\n\n// ── Built-in Infix Operator Binding Power Table ──────────────────────────────\n// Pre-computed Uint8Array lookup indexed by token typeId.\n// value > 0 → built-in infix operator with that binding power\n// value = 0 → not a built-in infix, fall through to Tier 2 parselet registry\n//\n// Built at module load via buildBindingPowerTable(). The table is sparse\n// most entries are 0 since only ~15 of 80+ token types are infix operators.\n//\n// Performance: Uint8Array[typeId] is a single typed array load, no Map.get()\n// no string hashing, no property chain. V8 eliminates bounds checks when typeId\n// is known to be within array length.\n\nimport { TokenTypes } from \"@solve-js/lexer/Token\";\nimport { tokenTypeId } from \"@solve-js/lexer/Token\";\n\n/**\n * Mapping of token type names → binding powers for built-in infix operators.\n * Only operators listed here get the Tier 1 fast path in PrecedenceParser.\n * All other infix tokens use the Tier 2 parselet registry fallback.\n */\nexport const BUILTIN_INFIX_BP: Record<string, number> = {\n // Arithmetic (infix, left-associative)\n [TokenTypes.PLUS]: BindingPower.Sum,\n [TokenTypes.MINUS]: BindingPower.Sum,\n [TokenTypes.STAR]: BindingPower.Product,\n [TokenTypes.SLASH]: BindingPower.Product,\n [TokenTypes.MOD]: BindingPower.Product,\n\n // Arithmetic (infix, RIGHT-associative, PrecedenceParser handles this specially)\n [TokenTypes.CARET]: BindingPower.Exponent,\n\n // Bitwise and shift (infix, left-associative), one level each, ordered as C\n // and JavaScript order them. `>>>` used to be missing from this table\n // entirely, which left it running at its Tier 2 parselet level while `>>`\n // ran at the Tier 1 one, so \"16 >> 3 & 1\" and \"16 >>> 3 & 1\" grouped\n // differently and answered 0 and 8.\n [TokenTypes.BIT_OR]: BindingPower.BitwiseOr,\n [TokenTypes.BIT_XOR]: BindingPower.BitwiseXor,\n [TokenTypes.BIT_AND]: BindingPower.BitwiseAnd,\n [TokenTypes.LSHIFT]: BindingPower.Shift,\n [TokenTypes.RSHIFT]: BindingPower.Shift,\n [TokenTypes.URSHIFT]: BindingPower.Shift,\n\n // Postfix (no right operand, PrecedenceParser handles this specially)\n [TokenTypes.PERCENT]: BindingPower.Postfix,\n\n // Percentage keyword (infix, left-associative: \"50% of 200\" → MUL)\n [TokenTypes.OF]: BindingPower.Product,\n};\n\n// Note: These token types are intentionally NOT in the BP_TABLE, they stay in\n// the Tier 2 parselet registry because they require complex handling:\n// IN, TO → UoM conversion parselets (peek at target unit token, complex logic)\n// DOT → Property access (chained OBJ_GET, needs left-token tracking)\n// EQUALS → Assignment (VariableParselet handles :var = expr pattern)\n// EQUALITY, NEQ, GTE, LTE → Comparison ops (need dedicated VM opcodes, task 2.15a)\n// COMMA → Argument separator (function calls, array/object literals)\n\n/** Cached BP_TABLE, built once at module load, immutable thereafter. */\nlet _bpTable: Uint8Array | null = null;\n\n/**\n * Build the Uint8Array binding power table indexed by token typeId.\n * Idempotent, returns cached table on subsequent calls.\n *\n * Must be called after all token types are registered (via registerAllTokenTypes())\n * and after plugin providers have registered their token types.\n */\nexport function buildBindingPowerTable(): Uint8Array {\n if (_bpTable) return _bpTable;\n\n // Size to the largest registered typeId + 1\n let maxId = 0;\n for (const name of Object.keys(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n // Also scan all TokenTypes to ensure table covers all registered IDs\n for (const name of Object.values(TokenTypes)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n\n const table = new Uint8Array(maxId + 1);\n for (const [name, bp] of Object.entries(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n table[id] = bp;\n }\n\n _bpTable = table;\n return table;\n}\n\n/**\n * Drop the cached table, so the next {@link buildBindingPowerTable} call builds\n * a fresh one sized to the token types registered by then.\n *\n * It does NOT add a plugin's operator to the Tier 1 fast path, which is what\n * this comment used to promise. The values in the table come from\n * `BUILTIN_INFIX_BP`, which is module-private and has no registration path, so\n * a rebuilt table holds the same binding powers and a plugin token still reads\n * 0. `PrecedenceParser.BP_TABLE` is a static initialized once at class\n * definition time and never re-read, so it would not see a rebuild anyway.\n *\n * A plugin's infix operator takes the Tier 2 parselet-registry route instead,\n * which is where an operator whose binding power the engine does not already\n * know is meant to live.\n */\nexport function invalidateBindingPowerTable(): void {\n _bpTable = null;\n}\n","import { OpCode } from \"@solve-js/parser/OpCode\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * `BytecodeProgram.opcodes` is a `Uint8Array`, every operand written into\n * it (including constant-pool indices from {@link BytecodeBuilder.emitNumber}/\n * {@link BytecodeBuilder.emitString}) is truncated to a single byte on\n * `build()`. Exceeding this silently wraps the index (e.g. entry 300 reads\n * back as entry 44), producing a wrong result with no error. See\n * {@link BytecodeBuilder.emitNumber} for the guard that turns this into a\n * thrown error instead.\n */\nconst MAX_CONSTANT_POOL_INDEX = 255;\n\n/** The `numberIndex` key for negative zero, which `Map` would otherwise fold into positive zero. */\nconst NEGATIVE_ZERO_KEY = \"-0\";\n\n/**\n * An operand that fits the byte the opcode stream stores it in, or a\n * structured refusal. `build()` copies the stream into a `Uint8Array`, which\n * keeps the low eight bits of whatever it is given: an operand of 300 used to\n * become 44 with no error, and the program then read a different constant,\n * plugin function or argument count from the one the parselet emitted. Every\n * raw operand goes through here, so a package author's mistake is reported at\n * compile time as a fault in the package rather than answered with a wrong\n * number.\n */\nfunction checkedOperand(value: number, what: string): number {\n\tif (!Number.isInteger(value) || value < 0 || value > 255) {\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t`A bytecode ${what} must be an integer from 0 to 255, but ${value} was emitted; the opcode stream stores one byte per operand.`,\n\t\t\t{ value, what }\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * Compiled bytecode program produced by {@link BytecodeBuilder}.\n * Ready for consumption by {@link executeBytecode} without further processing.\n */\nexport interface BytecodeProgram {\n\topcodes: Uint8Array;\n\tnumbers: Float64Array;\n\tstrings: string[];\n\t/**\n\t * Numeric constants by opcode position, restored from a snapshot.\n\t *\n\t * Nothing in the compile path writes this: numbers are emitted inline into\n\t * {@link numbers} instead. `build()` used to attach an empty Map to every\n\t * program anyway, which was one allocation per compiled expression, around a\n\t * tenth of parse-and-compile time, for a collection that was never read.\n\t * It is left off now, and only {@link EngineSnapshot} sets it when restoring\n\t * a program that carried one; every reader already guards on its absence.\n\t */\n\tconstants?: Map<number, number>;\n\t/**\n\t * Whether the program contains any async opcodes (CALL_PLUGIN, etc.).\n\t * Set during compilation by the BytecodeBuilder. Allows the engine\n\t * to skip the O(n) resolver preflight check in O(1) for purely\n\t * synchronous expressions like `2 + 2`.\n\t */\n\thasAsync: boolean;\n\t/**\n\t * User-defined-function bodies compiled alongside this program (one\n\t * entry per `name(params) = body` definition on this line). See\n\t * {@link BytecodeBuilder.emitUserFunctionBody}. `OpCode.DEFINE_USER_FUNCTION`'s\n\t * operand is an index into this array, resolved at VM-execution time\n\t * (not parse time) so a diagnostic/lookahead parse that never actually\n\t * executes the definition line has no side effect on `vm.userFunctions`.\n\t */\n\tuserFunctionBodies?: UserFunctionDef[];\n\t/**\n\t * Anonymous function bodies compiled alongside this program, one entry\n\t * per `map`/`reduce` inline transform expression (e.g. the `10*x` in\n\t * `map(10*x, [0,1,500])`). See {@link BytecodeBuilder.emitAnonymousBody}.\n\t * Deliberately a SEPARATE side-table from `userFunctionBodies`, not\n\t * routed through `vm.userFunctions` at all: an inline body has no name\n\t * and must never leak into the persistent name-keyed registry the way\n\t * a real `f(x) = ...` definition does.\n\t */\n\tanonymousBodies?: AnonymousBodyDef[];\n}\n\n/**\n * An anonymous transform body for `map`/`reduce`'s inline-expression form\n * (e.g. `10*x` in `map(10*x, [0,1,500])`, or `acc+x` in `reduce(acc+x,\n * [1,2,3])`). Structurally identical to {@link UserFunctionDef} minus the\n * `name`. See `OpCode.MAP_INVOKE`/`REDUCE_INVOKE` and\n * `vm/VM.ts`'s handlers, which build a call frame from `params`/`args`\n * exactly like `CALL_USER_FUNCTION` does, just without ever registering\n * the body in `vm.userFunctions`.\n */\nexport interface AnonymousBodyDef {\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * A user-defined, parameterized, reusable function's compiled form\n * (`f(x) = 2*x + 1`). See `OpCode.DEFINE_USER_FUNCTION`/`CALL_USER_FUNCTION`\n * and `vm/VM.ts`'s `VM.defineUserFunction`/`getUserFunction`.\n *\n * `program` is the body compiled to its OWN independent `BytecodeProgram`,\n * not a fragment of the definition line's own bytecode. Parameter names\n * inside the body compile to ORDINARY `LOAD_VAR <name>` opcodes, no\n * parse-time rewriting, because parameter resolution happens dynamically\n * at the VM level: `CALL_USER_FUNCTION` pushes a name-keyed call frame\n * (`Map<string, Value>`) before re-executing `program`, and `VM.getVar()`\n * checks the innermost call frame before falling back to the flat\n * document-variable store. This is why a `UNIT`-collision parameter name\n * (e.g. `h` in `area(w, h) = w * h`, which lexes as the \"hour\" unit) needs\n * no special handling anywhere, it's just another `LOAD_VAR \"h\"`, resolved\n * the same way as any other name.\n */\nexport interface UserFunctionDef {\n\tname: string;\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * Shared empty collections for programs that emit none.\n *\n * `build()` runs once per compiled expression, so an empty array allocated\n * there is an allocation per line of every document. Most programs emit no\n * strings at all (only the unit and datetime parselets do), and one that emits\n * no numbers is common too, so both were routinely allocating an empty\n * container that nothing would ever read.\n *\n * Sharing them is safe because a built program is read-only downstream: the VM\n * and the snapshot writer only index and iterate these, and nothing in the\n * engine pushes to `program.strings` or `program.numbers`. They are frozen so\n * that a future writer fails loudly here rather than silently corrupting every\n * other program that shares the instance.\n */\nconst EMPTY_STRINGS: readonly string[] = Object.freeze([]);\nconst EMPTY_NUMBERS = new Float64Array(0);\n\n/**\n * Direct-to-bytecode compiler for the Pratt parser.\n *\n * Accumulates opcodes, numeric constants, and string references during parsing,\n * then produces a {@link BytecodeProgram} for VM execution. Supports:\n * - Standard build via {@link build}\n * - Zero-copy build into pre-allocated buffers via {@link buildInto}\n * - In-place reset for reuse without reallocation\n */\nexport class BytecodeBuilder {\n\tprivate opcodes: number[] = [];\n\tprivate numbers: number[] = [];\n\tprivate strings: string[] = [];\n\tprivate stringIndex = new Map<string, number>();\n\t/** Value (or {@link NEGATIVE_ZERO_KEY}) to its slot in `numbers`, so a repeated literal is emitted once. */\n\tprivate numberIndex = new Map<number | string, number>();\n\tprivate _hasAsync = false;\n\tprivate userFunctionBodies: UserFunctionDef[] = [];\n\tprivate anonymousBodies: AnonymousBodyDef[] = [];\n\n\t/**\n\t * The per-engine `plugin function name -> registry index` map, wired in by\n\t * the engine so {@link emitPluginCall} can resolve a name at emit time. The\n\t * same object reference is shared with every builder in an engine (the pool\n\t * and each ad-hoc nested-body builder), and the engine populates it as\n\t * packages register, so a parselet never sees the numeric index.\n\t */\n\tconstructor(private readonly pluginFunctionIndex?: ReadonlyMap<string, number>) {}\n\n\t/** The name->index map, so a nested-body builder inherits the same resolution. */\n\tget pluginIndexMap(): ReadonlyMap<string, number> | undefined {\n\t\treturn this.pluginFunctionIndex;\n\t}\n\n\t/**\n\t * Emit a plugin-function call by NAME. The engine assigns each registered\n\t * `pluginFunctions` entry an index at registration; this resolves the name to\n\t * that index and emits `CALL_PLUGIN` + index + argCount. Package authors emit\n\t * through this rather than a hand-allocated index.\n\t */\n\temitPluginCall(name: string, argCount: number): void {\n\t\tconst index = this.pluginFunctionIndex?.get(name);\n\t\tif (index === undefined) {\n\t\t\tthrow ErrorFactory.execution(\n\t\t\t\t\"UNKNOWN_PLUGIN_FUNCTION\",\n\t\t\t\t`No registered plugin function named \"${name}\". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,\n\t\t\t\t{ functionName: name },\n\t\t\t);\n\t\t}\n\t\t// One byte covers the first 256 plugin functions; beyond that, the\n\t\t// wide opcode carries a two-byte little-endian index. Emitting the\n\t\t// narrow form whenever it fits keeps existing bytecode and snapshots\n\t\t// byte-for-byte unchanged. The index cannot exceed 65535 because the\n\t\t// allocator (allocatePluginFunctionIndex) caps it, but guard anyway so\n\t\t// a stray index is a clear error rather than a silently truncated byte.\n\t\tif (index > 0xffff) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"PLUGIN_FUNCTION_INDEX_TOO_LARGE\",\n\t\t\t\t`Plugin-function index ${index} exceeds the two-byte bytecode limit (65535).`,\n\t\t\t\t{ index },\n\t\t\t);\n\t\t}\n\t\tif (index <= 0xff) {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN);\n\t\t\tthis.emitIndex(index);\n\t\t} else {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN_WIDE);\n\t\t\tthis.emitIndex(index & 0xff); // low byte\n\t\t\tthis.emitIndex((index >> 8) & 0xff); // high byte\n\t\t}\n\t\tthis.emitIndex(argCount);\n\t}\n\n\t/** Emit an {@link OpCode} instruction. */\n\temitOpcode(op: OpCode): void {\n\t\tthis.opcodes.push(op);\n\t\tif (op === OpCode.CALL_PLUGIN || op === OpCode.CALL_PLUGIN_WIDE) {\n\t\t\tthis._hasAsync = true;\n\t\t}\n\t}\n\n\t/**\n\t * Emit a numeric literal: interns `n` into the program's constant pool\n\t * (deduplicated, like {@link emitString}) and writes its index into the\n\t * opcode stream (read back by the VM as e.g. `PUSH_NUMBER <idx>`).\n\t *\n\t * Deduplicated so that the 256-entry pool counts distinct values rather\n\t * than occurrences: a long line of repeated literals used to exhaust it\n\t * long before it held 256 different numbers. Negative zero keeps its own\n\t * slot, because `1 / -0` is not `1 / 0`; NaN shares one, since every NaN\n\t * reads the same.\n\t *\n\t * @throws If the pool would exceed 256 distinct entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst key = Object.is(n, -0) ? NEGATIVE_ZERO_KEY : n;\n\t\tlet idx = this.numberIndex.get(key);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.numbers.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.numbers.push(n);\n\t\t\tthis.numberIndex.set(key, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a string literal: interns `s` into the program's string pool\n\t * (deduplicated via `stringIndex`) and writes its index into the opcode\n\t * stream. Subject to the same constant-pool bound as {@link emitNumber},\n\t * but since strings ARE deduplicated, only distinct string values count\n\t * against the limit.\n\t *\n\t * @throws If the string pool would exceed 256 distinct entries.\n\t */\n\temitString(s: string): void {\n\t\tlet idx = this.stringIndex.get(s);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.strings.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_STRING_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct string literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.strings.push(s);\n\t\t\tthis.stringIndex.set(s, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a raw numeric operand (0-255) following an opcode, e.g. a\n\t * plugin-function index for `CALL_PLUGIN`, or an argument count. Unlike\n\t * {@link emitOpcode}, this does not go through the `OpCode` enum, so\n\t * package authors use this (not an unsafe cast to `OpCode`) to push\n\t * operands their own opcode handler expects to read positionally.\n\t */\n\temitIndex(idx: number): void {\n\t\tthis.opcodes.push(checkedOperand(idx, \"index\"));\n\t}\n\n\t/** Emit a raw byte (0-255), used for fixed small operands like argument counts. */\n\temitByte(b: number): void {\n\t\tthis.opcodes.push(checkedOperand(b, \"byte\"));\n\t}\n\n\t/** Number of opcodes/operands emitted so far, used to compute jump targets before {@link patchJump}. */\n\tget currentLength(): number {\n\t\treturn this.opcodes.length;\n\t}\n\n\t/**\n\t * Register a compiled user-defined-function body, returning its index\n\t * into this program's `userFunctionBodies` side-table, the caller emits\n\t * that index as `DEFINE_USER_FUNCTION`'s operand via {@link emitIndex}.\n\t * Subject to the same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitNumber}/{@link emitString} (the index itself is a single\n\t * opcode-stream byte), in practice a single line defines at most a\n\t * handful of functions, so this limit is never realistically reached.\n\t *\n\t * @throws If more than 256 function bodies are registered on one program.\n\t */\n\temitUserFunctionBody(name: string, params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.userFunctionBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_FUNCTION_DEFINITIONS\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} function definitions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.userFunctionBodies.push({ name, params, program });\n\t\treturn idx;\n\t}\n\n\t/**\n\t * Register a compiled `map`/`reduce` anonymous transform body, returning\n\t * its index into this program's `anonymousBodies` side-table, the\n\t * caller emits that index as `MAP_INVOKE`/`REDUCE_INVOKE`'s operand via\n\t * {@link emitIndex}. Same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitUserFunctionBody}.\n\t *\n\t * @throws If more than 256 anonymous bodies are registered on one program.\n\t */\n\temitAnonymousBody(params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.anonymousBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_ANONYMOUS_BODIES\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.anonymousBodies.push({ params, program });\n\t\treturn idx;\n\t}\n\n\t/** Overwrite a previously-emitted placeholder operand at `position` with the real jump `target`, once known. */\n\tpatchJump(position: number, target: number): void {\n\t\tif (position < 0 || position >= this.opcodes.length) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t\t`patchJump was asked to write at position ${position}, outside the ${this.opcodes.length} bytes emitted so far.`,\n\t\t\t\t{ position, length: this.opcodes.length }\n\t\t\t);\n\t\t}\n\t\tthis.opcodes[position] = checkedOperand(target, \"jump target\");\n\t}\n\n\t/**\n\t * Build the accumulated opcodes/numbers/strings into a BytecodeProgram.\n\t * Creates new TypedArrays, the builder can be reused after this call.\n\t */\n\tbuild(): BytecodeProgram {\n\t\treturn {\n\t\t\topcodes: new Uint8Array(this.opcodes),\n\t\t\tnumbers: this.numbers.length > 0 ? new Float64Array(this.numbers) : EMPTY_NUMBERS,\n\t\t\t// Defensive copy when there is anything to copy: reset()'s\n\t\t\t// `.length = 0` would otherwise clear a reference the program still\n\t\t\t// holds. An empty one needs no copy, so it shares the frozen\n\t\t\t// singleton instead of allocating per program.\n\t\t\tstrings: this.strings.length > 0 ? [...this.strings] : (EMPTY_STRINGS as string[]),\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Build directly into a pre-allocated buffer for zero-copy VM consumption.\n\t *\n\t * When `buf` is provided and large enough, writes into it and returns\n\t * subarray **views** (not copies), the returned TypedArrays share the\n\t * buffer's underlying ArrayBuffer. The caller MUST NOT mutate the buffer\n\t * until the returned BytecodeProgram is no longer needed.\n\t *\n\t * If the caller intends to cache the result, they must copy the TypedArrays\n\t * (e.g. `new Uint8Array(program.opcodes)`) before reusing the buffer pool.\n\t *\n\t * When `buf` is omitted or too small, allocates fresh TypedArrays.\n\t */\n\tbuildInto(buf?: { opcodes: Uint8Array; numbers: Float64Array }): BytecodeProgram {\n\t\tconst opLen = this.opcodes.length;\n\t\tconst numLen = this.numbers.length;\n\n\t\tconst reuseOpcodes = buf && buf.opcodes.length >= opLen;\n\t\tconst reuseNumbers = buf && buf.numbers.length >= numLen;\n\n\t\t// Subarray views that share the buffer's ArrayBuffer (zero-copy)\n\t\tconst opcodes = reuseOpcodes\n\t\t\t? new Uint8Array(buf!.opcodes.buffer, buf!.opcodes.byteOffset, opLen)\n\t\t\t: new Uint8Array(opLen);\n\t\tconst numbers = reuseNumbers\n\t\t\t? new Float64Array(buf!.numbers.buffer, buf!.numbers.byteOffset, numLen)\n\t\t\t: new Float64Array(numLen);\n\n\t\t// Write data into the views\n\t\tfor (let i = 0; i < opLen; i++) opcodes[i] = this.opcodes[i];\n\t\tfor (let i = 0; i < numLen; i++) numbers[i] = this.numbers[i];\n\n\t\treturn {\n\t\t\topcodes,\n\t\t\tnumbers,\n\t\t\tstrings: [...this.strings],\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\treset(): void {\n\t\t// Retain backing stores with .length = 0 to avoid reallocation on growth.\n\t\t// = [] discards the ArrayBuffer, forcing V8 to reallocate on every push()\n\t\t// threshold (4→8→16→32...). For a 50-opcode expression, that's 3-4 copies.\n\t\tthis.opcodes.length = 0;\n\t\tif (this.numbers.length > 0) {\n\t\t\tthis.numbers.length = 0;\n\t\t\tthis.numberIndex.clear();\n\t\t}\n\t\t// Guarded on being non-empty. reset() runs once per compiled expression\n\t\t// and a CPU profile put it at over a tenth of parse-and-compile, which\n\t\t// is a lot for clearing collections that are usually already empty:\n\t\t// most expressions emit no strings, and user function bodies are rarer\n\t\t// still. Emptying an empty Map is not free, and neither is the write\n\t\t// barrier on a length assignment.\n\t\tif (this.strings.length > 0) {\n\t\t\tthis.strings.length = 0;\n\t\t\tthis.stringIndex.clear();\n\t\t}\n\t\tthis._hasAsync = false;\n\t\tif (this.userFunctionBodies.length > 0) this.userFunctionBodies.length = 0;\n\t\tif (this.anonymousBodies.length > 0) this.anonymousBodies.length = 0;\n\t}\n}\n","/**\n * Turning a `123n` literal's source text into the digits `PUSH_BIGINT` stores.\n *\n * The lexer coalesces thousands groups into the number token it is building,\n * accepting both `,` and `.` as the separator regardless of locale (see\n * `lexer/ExpressionLexer.ts`'s \"Thousands separators\" block). For a NUMBER that\n * is fine, because the separators are stripped again when the text is turned\n * into a double. For a BIGINT nothing stripped them: both consumers took the\n * token text, removed the trailing `n`, and handed the rest straight to\n * `BigInt()`.\n *\n * So `1.000n` reached `BigInt(\"1.000\")`, which throws a raw `SyntaxError` that\n * arrived at the host as UNEXPECTED_ERROR/INTERNAL: the engine reporting its\n * own bug for six characters a user typed. `1.01n` and `1.1n` were fine, which\n * is the tell that the `n` suffix was never the problem, the three-digit\n * thousands group was: a dot followed by exactly three digits is what the lexer\n * swallows, and one followed by one or two digits it leaves alone.\n *\n * Written once here rather than inline at both call sites. There are two\n * (`parser/PrecedenceParser.ts`'s Tier-1 switch and\n * `packages/biginteger/parselets/BigIntNumberParselet.ts`), they already held\n * identical copies of the `n`-stripping, and the two tiers disagreeing about a\n * literal is a bug shape this codebase has had before.\n *\n * @module BigIntLiteral\n */\n\nimport { getLocale } from \"@solve-js/constants/locales\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Two or more dot-separated groups of three, e.g. `1.234.567`.\n *\n * Unambiguous in any locale, since no locale writes two decimal points, so this\n * is stripped without consulting one. Same regex and same reasoning as\n * `NumberParselet.ts`'s copy for the NUMBER path.\n */\nconst CHAINED_DOT_THOUSANDS_GROUPS = /^\\d{1,3}(\\.\\d{3}){2,}$/;\n\n/** Digits and nothing else, which is what `BigInt()` can be handed safely. */\nconst DIGITS_ONLY = /^\\d+$/;\n\n/**\n * The digit string behind a bigint literal.\n *\n * A bigint literal has no fractional part by construction: the lexer only emits\n * BIGINT when it saw no decimal point of its own and no exponent, so any `.` or\n * `,` still in the text got there as a thousands group. Which of the two the\n * writer meant is a locale question, and answering it wrongly would silently\n * change the value by three orders of magnitude, so only the separator this\n * locale actually uses for grouping is removed. Anything left over is refused\n * rather than guessed at.\n *\n * @param raw - The token's text, with or without the trailing `n`.\n * @param localeCode - The engine's active locale.\n * @returns A string of digits, ready for `BigInt()`.\n * @throws An `INVALID_NUMBER_LITERAL` parsing error when what is left is not a\n * whole number, e.g. `1.000n` in a locale that writes decimals with a dot.\n */\nexport function bigIntLiteralDigits(raw: string, localeCode: string): string {\n\tconst withoutSuffix = raw.endsWith(\"n\") ? raw.slice(0, -1) : raw;\n\n\t// The common case first: nothing was grouped, so there is nothing to decide.\n\tif (DIGITS_ONLY.test(withoutSuffix)) return withoutSuffix;\n\n\tconst digits = CHAINED_DOT_THOUSANDS_GROUPS.test(withoutSuffix)\n\t\t? withoutSuffix.split(\".\").join(\"\")\n\t\t: stripLocaleGrouping(withoutSuffix, localeCode);\n\n\tif (!DIGITS_ONLY.test(digits)) {\n\t\tconst separator = withoutSuffix.includes(\".\") ? \".\" : withoutSuffix.includes(\",\") ? \",\" : withoutSuffix;\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"INVALID_NUMBER_LITERAL\",\n\t\t\t`\"${raw}\" is not a whole number: \"${separator}\" separates decimals in the ${localeCode} locale, and a whole number cannot have a fractional part.`,\n\t\t\t{ raw, localeCode, separator },\n\t\t);\n\t}\n\treturn digits;\n}\n\n/**\n * Removes the active locale's own thousands separator and nothing else.\n *\n * @param text - The literal without its `n`.\n * @param localeCode - The engine's active locale.\n * @returns The text with grouping removed, which the caller then re-checks.\n */\nfunction stripLocaleGrouping(text: string, localeCode: string): string {\n\tconst thousandsSeparator = getLocale(localeCode).display.thousandsSeparator;\n\treturn thousandsSeparator ? text.split(thousandsSeparator).join(\"\") : text;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkE4HAKNBQ_cjs=require('./chunk-E4HAKNBQ.cjs'),chunkGXO7TSXQ_cjs=require('./chunk-GXO7TSXQ.cjs');function x(m,n,e){let r=Math.trunc(m),o=Math.trunc(n),a=Math.trunc(e);if(!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(a))return Number.NaN;let t=r+Math.floor(o/12),i=(o%12+12)%12+1,s=t-(i<=2?1:0),l=Math.floor(s/400),u=s-l*400,N=Math.floor((153*(i+(i>2?-3:9))+2)/5),c=u*365+Math.floor(u/4)-Math.floor(u/100)+N;return l*146097+c-719468+(a-1)}function F(m){if(!Number.isFinite(m))return {year:Number.NaN,month0:Number.NaN,day:Number.NaN};let n=Math.trunc(m)+719468,e=Math.floor(n/146097),r=n-e*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),a=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),t=Math.floor((5*a+2)/153),i=a-Math.floor((153*t+2)/5)+1,s=t<10?t+3:t-9;return {year:o+e*400+(s<=2?1:0),month0:s-1,day:i}}var P=Object.freeze({year:Number.NaN,month0:Number.NaN,day:Number.NaN,weekday:Number.NaN,hour:Number.NaN,minute:Number.NaN,second:Number.NaN,millisecond:Number.NaN}),Z=864e13,d=864e5;function D(m){return !Number.isFinite(m)||Math.abs(m)>Z?Number.NaN:Math.trunc(m)}function z(m,n,e,r,o,a,t){let i=Math.trunc(r)*36e5+Math.trunc(o)*6e4+Math.trunc(a)*1e3+Math.trunc(t);return {dayNumber:x(m,n,e)+Math.floor(i/d),timeOfDay:(i%d+d)%d}}var S=/^([+-]\d{6}|\d{4})(?:-(\d{2})(?:-(\d{2}))?)?(?:[Tt](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?)?([Zz]|[+-]\d{2}:?\d{2})?$/,k=class{constructor(n,e={}){A(n),this.temporal=n;let r=e.timeZone??n.Now.timeZoneId(),o;try{o=n.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(r);}catch(a){throw chunkGXO7TSXQ_cjs.c.config(chunkGXO7TSXQ_cjs.r.TEMPORAL_TIME_ZONE_UNKNOWN,`The Temporal implementation does not know the time zone "${r}"`,{timeZone:r,cause:a instanceof Error?a.message:String(a)})}this.timeZone=o.timeZoneId,this.clock=e.now??(()=>n.Now.instant().epochMilliseconds);}now(){return this.clock()}fields(n){let e=this.zoned(n,this.timeZone);return e===null?P:{year:e.year,month0:e.month-1,day:e.day,weekday:e.dayOfWeek%7,hour:e.hour,minute:e.minute,second:e.second,millisecond:e.millisecond}}localMidnight(n,e,r){return this.wallClock(n,e,r,0,0,0,0)}localWallClock(n,e,r,o){let a=this.localMidnight(n,e,r),t=this.fields(a);return Number.isNaN(t.year)?Number.NaN:this.wallClock(t.year,t.month0,t.day,t.hour,o,t.second,t.millisecond)}addDays(n,e){let r=this.fields(n);return Number.isNaN(r.year)?Number.NaN:this.wallClock(r.year,r.month0,r.day+e,r.hour,r.minute,r.second,r.millisecond)}addMonths(n,e){let r=this.fields(n);if(Number.isNaN(r.year))return Number.NaN;let o=r.day,a=this.fields(this.wallClock(r.year,r.month0,1,r.hour,r.minute,r.second,r.millisecond));if(Number.isNaN(a.year))return Number.NaN;let t=this.fields(this.wallClock(a.year,a.month0+e,a.day,a.hour,a.minute,a.second,a.millisecond));if(Number.isNaN(t.year))return Number.NaN;let i=Math.min(o,chunkE4HAKNBQ_cjs.b(t.year,t.month0));return this.wallClock(t.year,t.month0,i,t.hour,t.minute,t.second,t.millisecond)}utcOffsetMinutes(n){let e=this.zoned(n,this.timeZone);return e===null?Number.NaN:Math.trunc(e.offsetNanoseconds/6e10)||0}parseIso8601(n){let e=S.exec(n);if(e===null)return Number.NaN;let[,r,o,a,t,i,s,l,u]=e;if(r==="-000000")return Number.NaN;let N=Number(r),c=o===void 0?1:Number(o),f=a===void 0?1:Number(a),b=t===void 0?0:Number(t),h=i===void 0?0:Number(i),y=s===void 0?0:Number(s),I=l===void 0?0:Number(l.slice(0,3).padEnd(3,"0"));if(c<1||c>12||f<1||f>31||b>24||h>59||y>59||b===24&&(h!==0||y!==0||I!==0))return Number.NaN;let p=z(N,c-1,f,b,h,y,I);if(u===void 0&&t!==void 0)return this.resolve(p);let g=0;if(u!==void 0&&u!=="Z"&&u!=="z"){let _=u.slice(1).replace(":",""),w=Number(_.slice(0,2)),C=Number(_.slice(2,4));if(w>23||C>59)return Number.NaN;g=(u[0]==="-"?-1:1)*(w*60+C);}let O=p.dayNumber*d+p.timeOfDay-g*6e4;return Math.abs(O)>Z?Number.NaN:O}formatLongDate(n,e){let r=D(n);return Number.isNaN(r)?"Invalid Date":new Intl.DateTimeFormat(e,{timeZone:this.timeZone,weekday:"long",year:"numeric",month:"long",day:"numeric"}).format(r)}formatTimeOfDay(n,e){let r=D(n);return Number.isNaN(r)?"Invalid Date":new Intl.DateTimeFormat(e,{timeZone:this.timeZone,hour:"numeric",minute:"numeric",second:"numeric"}).format(r)}zoneOffsetMinutes(n,e){let r=Number.isFinite(e)?Math.trunc(e):e,o=this.temporal.Instant.fromEpochMilliseconds(r).toZonedDateTimeISO(n),a=Math.floor((r+o.offsetNanoseconds/1e6)/1e3)*1e3;return Math.round((a-e)/6e4)||0}fieldsInZone(n,e){let r=Number.isFinite(e)?Math.trunc(e):e,o=this.temporal.Instant.fromEpochMilliseconds(r).toZonedDateTimeISO(n);return {year:o.year,month0:o.month-1,day:o.day,hour:o.hour,minute:o.minute,second:o.second}}zone(){return this.timeZone}formatTimeInZone(n,e){return chunkE4HAKNBQ_cjs.m(n,e)}formatDateInZone(n,e){return chunkE4HAKNBQ_cjs.n(n,e)}zoned(n,e){let r=D(n);if(Number.isNaN(r))return null;try{return this.temporal.Instant.fromEpochMilliseconds(r).toZonedDateTimeISO(e)}catch{return null}}wallClock(n,e,r,o,a,t,i){let s=n>=0&&n<=99?1900+Math.trunc(n):n;return this.resolve(z(s,e,r,o,a,t,i))}resolve(n){let e=F(n.dayNumber);if(Number.isNaN(e.year))return Number.NaN;let r=Math.floor(n.timeOfDay/36e5),o=Math.floor(n.timeOfDay/6e4)%60,a=Math.floor(n.timeOfDay/1e3)%60,t=n.timeOfDay%1e3;try{let s=this.temporal.PlainDateTime.from({year:e.year,month:e.month0+1,day:e.day,hour:r,minute:o,second:a,millisecond:t},{overflow:"reject"}).toZonedDateTime(this.timeZone,{disambiguation:"compatible"}).epochMilliseconds;return Math.abs(s)>Z?Number.NaN:s}catch{return Number.NaN}}};function A(m){let n=m,e=typeof n?.Now?.instant!="function"?"Now.instant":typeof n?.Now?.timeZoneId!="function"?"Now.timeZoneId":typeof n?.Instant?.fromEpochMilliseconds!="function"?"Instant.fromEpochMilliseconds":typeof n?.PlainDateTime?.from!="function"?"PlainDateTime.from":null;if(e!==null)throw chunkGXO7TSXQ_cjs.c.config(chunkGXO7TSXQ_cjs.r.TEMPORAL_IMPLEMENTATION_INVALID,`createTemporalCalendar needs a Temporal implementation (globalThis.Temporal on a runtime that ships it, or a polyfill's export); the value given has no ${e}`,{missing:e})}function q(m,n={}){return new k(m,n)}exports.a=k;exports.b=q;//# sourceMappingURL=chunk-ZE5KKMBV.cjs.map
2
+ //# sourceMappingURL=chunk-ZE5KKMBV.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/temporal/CivilDays.ts","../src/temporal/TemporalCalendar.ts"],"names":["civilDayNumber","year","month0","day","y0","m0","d","y","m","shiftedYear","era","yearOfEra","dayOfYear","dayOfEra","civilFromDayNumber","days","z","monthFromMarch","month","NAN_FIELDS","MAX_INSTANT","MS_PER_DAY","clip","epochMs","normaliseWallClock","hour","minute","second","millisecond","time","ISO_DATE_TIME","TemporalCalendar","temporal","options","assertTemporalLike","requested","probe","error","ErrorFactory","CoreErrorCodes","minutesPastMidnight","anchored","a","f","months","f0","dayOfMonth","f1","f2","daysInMonth","text","yearText","monthText","dayText","hourText","minuteText","secondText","fractionText","zoneText","wall","offsetMinutes","digits","offsetHours","offsetMinutesPart","instant","locale","t","zone","wallSecond","timeInZone","dateInZone","windowed","civil","candidate","missing","createTemporalCalendar"],"mappings":"qHAkDO,SAASA,EAAeC,CAAAA,CAAcC,CAAAA,CAAgBC,CAAAA,CAAqB,CACjF,IAAMC,CAAAA,CAAK,IAAA,CAAK,KAAA,CAAMH,CAAI,EACpBI,CAAAA,CAAK,IAAA,CAAK,KAAA,CAAMH,CAAM,EACtBI,CAAAA,CAAI,IAAA,CAAK,KAAA,CAAMH,CAAG,EACxB,GAAI,CAAC,MAAA,CAAO,QAAA,CAASC,CAAE,CAAA,EAAK,CAAC,MAAA,CAAO,QAAA,CAASC,CAAE,CAAA,EAAK,CAAC,OAAO,QAAA,CAASC,CAAC,EAAG,OAAO,MAAA,CAAO,GAAA,CAGv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`Temporal`\n * backend.\n *\n * `Date` normalises a set of wall-clock fields before it resolves them in a\n * zone: month 13 rolls into the next year, day 0 into the month before, a\n * time past midnight into the next day, and only the final instant is\n * clipped to the range `Date` represents. That is the `MakeDay` and\n * `MakeTime` order of the ECMAScript specification, and a backend built on\n * another library has to follow it to answer what `Date` answers on the last\n * representable day and for a rolled-over literal. `Date` does this\n * arithmetic inside its own setters, where a second backend cannot reach it,\n * so it is written out here with nothing clipped.\n *\n * Under `temporal/` rather than `calendar/Gregorian.ts` because only the\n * `Temporal` backend needs it: the `Date` backend gets the same arithmetic\n * from `Date` itself, and keeping it here keeps it out of the root entry's\n * bundle. The unit spec measures it against `Date.UTC` and `setUTCFullYear`\n * wherever `Date` can represent the date.\n *\n * @module CivilDays\n */\n\n/** A calendar date as year, zero-based month and day, the shape the civil-day arithmetic exchanges. */\nexport interface CivilDate {\n\treadonly year: number;\n\t/** Zero-based month: 0 is January, 11 is December. */\n\treadonly month0: number;\n\t/** Day of the month, from 1. */\n\treadonly day: number;\n}\n\n/**\n * The day number of a calendar date, counted from 1 January 1970, by\n * arithmetic alone: no `Date`, so no clip to the range `Date` represents.\n *\n * This is the `MakeDay` step of the ECMAScript specification, which a\n * backend needs unclipped: `Date` normalises a set of fields (month 13, day\n * 0, a time past midnight) before it resolves them in a zone and clips the\n * result, so a wall-clock time on the last representable day is an instant,\n * not `NaN`, and a backend built on another library must follow the same\n * order. An overflowing month or day rolls into the adjacent year or month,\n * as {@link utcMs}'s do, and a fractional field is truncated, as `Date`\n * truncates it.\n *\n * @param year - The calendar year, read as written.\n * @param month0 - Zero-based month; overflow rolls into the adjacent year.\n * @param day - Day of the month; overflow rolls into the adjacent month.\n * @returns Whole days since 1 January 1970, negative before it, or `NaN` when a field is not finite.\n */\nexport function civilDayNumber(year: number, month0: number, day: number): number {\n\tconst y0 = Math.trunc(year);\n\tconst m0 = Math.trunc(month0);\n\tconst d = Math.trunc(day);\n\tif (!Number.isFinite(y0) || !Number.isFinite(m0) || !Number.isFinite(d)) return Number.NaN;\n\t// Normalise the month into the year first, then count from the first of\n\t// that month, so a day of 0 or 40 is a plain offset from a real month.\n\tconst y = y0 + Math.floor(m0 / 12);\n\tconst m = ((m0 % 12) + 12) % 12 + 1;\n\t// The days-from-civil arithmetic, with the year taken to start in March\n\t// so a leap day is the last day of the cycle rather than an exception.\n\tconst shiftedYear = y - (m <= 2 ? 1 : 0);\n\tconst era = Math.floor(shiftedYear / 400);\n\tconst yearOfEra = shiftedYear - era * 400;\n\tconst dayOfYear = Math.floor((153 * (m + (m > 2 ? -3 : 9)) + 2) / 5);\n\tconst dayOfEra = yearOfEra * 365 + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100) + dayOfYear;\n\treturn era * 146_097 + dayOfEra - 719_468 + (d - 1);\n}\n\n/**\n * The calendar date of a day number, the inverse of {@link civilDayNumber}.\n *\n * @param days - Whole days since 1 January 1970, negative before it.\n * @returns The date, or `NaN` in every field when `days` is not finite.\n */\nexport function civilFromDayNumber(days: number): CivilDate {\n\tif (!Number.isFinite(days)) return { year: Number.NaN, month0: Number.NaN, day: Number.NaN };\n\tconst z = Math.trunc(days) + 719_468;\n\tconst era = Math.floor(z / 146_097);\n\tconst dayOfEra = z - era * 146_097;\n\tconst yearOfEra = Math.floor((dayOfEra - Math.floor(dayOfEra / 1460) + Math.floor(dayOfEra / 36_524) - Math.floor(dayOfEra / 146_096)) / 365);\n\tconst dayOfYear = dayOfEra - (365 * yearOfEra + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100));\n\tconst monthFromMarch = Math.floor((5 * dayOfYear + 2) / 153);\n\tconst day = dayOfYear - Math.floor((153 * monthFromMarch + 2) / 5) + 1;\n\tconst month = monthFromMarch < 10 ? monthFromMarch + 3 : monthFromMarch - 9;\n\tconst year = yearOfEra + era * 400 + (month <= 2 ? 1 : 0);\n\treturn { year, month0: month - 1, day };\n}\n","/**\n * The `Temporal` calendar backend: the engine's date questions answered\n * through a `Temporal` implementation the host supplies, in a time zone the\n * host chooses.\n *\n * `Temporal` is the JavaScript standard library's replacement for `Date`. It\n * ships unflagged in Node 26 and in current Chrome, Firefox and Deno, but not\n * in Safari nor in Node 22 and 24, and the smallest polyfill adds about twenty\n * kilobytes gzipped to a bundle. The engine therefore imports no `Temporal`\n * and no polyfill: this module is reached only through the\n * `solve-engine/temporal` entry, and the host hands it the implementation to\n * use, `globalThis.Temporal` on a runtime that has one or a polyfill's export.\n * A host that never imports the entry pays nothing for it.\n *\n * The backend answers exactly what the `Date` backend answers. That is a\n * design constraint rather than a hope: `Temporal` and `Date` differ in what\n * they do with an out-of-range instant (`RangeError` against `NaN`), a\n * fractional millisecond (a throw against truncation), a day past the end of\n * a month (a clamp or a throw against a roll into the next month) and a year\n * from 0 to 99 (read literally against read as the 1900s), and every one of\n * those is reproduced here the way `Date` does it, because the engine's\n * results are measured against `Date` and a host switching backends must see\n * no result move. The differential suite under `__tests__/temporal/` is what\n * holds that line.\n *\n * The one thing that does change is the zone. `Date` reads the process's own\n * zone and nothing else; this backend reads the zone it was constructed with,\n * so a document can be computed in Tokyo from a server in London, or in a\n * zone the reader picks. That is the capability the backend adds, and the\n * only observable difference.\n *\n * The named-zone display strings go through the same `Intl.DateTimeFormat`\n * helpers the `Date` backend uses (`calendar/IntlZone.ts`), and the zone-free\n * arithmetic through `calendar/Gregorian.ts`, so the two backends share one\n * implementation wherever an answer does not depend on which backend is in\n * use. The one piece of arithmetic `Date` keeps inside its own setters, the\n * normalisation of overflowing fields, is written out in `CivilDays.ts`.\n *\n * @module TemporalCalendar\n */\n\nimport type { CalendarBackend, CalendarFields, ZonedFields } from \"@solve-js/calendar/CalendarBackend\";\nimport { daysInMonth } from \"@solve-js/calendar/Gregorian\";\nimport { civilDayNumber, civilFromDayNumber } from \"./CivilDays\";\nimport { dateInZone, timeInZone } from \"@solve-js/calendar/IntlZone\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\nimport { CoreErrorCodes } from \"@solve-js/errors/ErrorCode\";\n\n/**\n * The part of a `Temporal.Instant` the backend reads: its epoch milliseconds,\n * and the zoned date-time it shows in a named zone.\n */\nexport interface TemporalInstantLike {\n\treadonly epochMilliseconds: number;\n\ttoZonedDateTimeISO(timeZone: string): TemporalZonedDateTimeLike;\n}\n\n/**\n * The part of a `Temporal.ZonedDateTime` the backend reads: the calendar\n * fields (a one-based month and an ISO weekday, Monday 1 to Sunday 7, both\n * translated at the boundary), the offset, and the instant.\n */\nexport interface TemporalZonedDateTimeLike {\n\treadonly year: number;\n\t/** One-based month, 1 is January, as `Temporal` counts. */\n\treadonly month: number;\n\treadonly day: number;\n\t/** ISO weekday: Monday is 1, Sunday is 7. */\n\treadonly dayOfWeek: number;\n\treadonly hour: number;\n\treadonly minute: number;\n\treadonly second: number;\n\treadonly millisecond: number;\n\t/** The zone's offset from UTC at this instant, in nanoseconds, positive when ahead. */\n\treadonly offsetNanoseconds: number;\n\treadonly epochMilliseconds: number;\n\t/** The zone's canonical IANA identifier. */\n\treadonly timeZoneId: string;\n}\n\n/** The part of a `Temporal.PlainDateTime` the backend uses: resolving a wall-clock time to an instant in a zone. */\nexport interface TemporalPlainDateTimeLike {\n\ttoZonedDateTime(\n\t\ttimeZone: string,\n\t\toptions?: { disambiguation?: \"compatible\" | \"earlier\" | \"later\" | \"reject\" },\n\t): TemporalZonedDateTimeLike;\n}\n\n/** The wall-clock fields a `Temporal.PlainDateTime` is built from, with a one-based month. */\nexport interface TemporalDateTimeFields {\n\tyear: number;\n\t/** One-based month, 1 is January. */\n\tmonth: number;\n\tday: number;\n\thour: number;\n\tminute: number;\n\tsecond: number;\n\tmillisecond: number;\n}\n\n/**\n * The subset of the `Temporal` namespace the backend uses, as a structural\n * type, so the engine compiles and ships with no `Temporal` type installed\n * and a host passes whichever implementation it has: `globalThis.Temporal`\n * on Node 26 or a current browser, or the export of a polyfill such as\n * `temporal-polyfill`. Both satisfy this shape as they are.\n */\nexport interface TemporalLike {\n\treadonly Now: {\n\t\tinstant(): TemporalInstantLike;\n\t\ttimeZoneId(): string;\n\t};\n\treadonly Instant: {\n\t\tfromEpochMilliseconds(epochMilliseconds: number): TemporalInstantLike;\n\t};\n\treadonly PlainDateTime: {\n\t\tfrom(fields: TemporalDateTimeFields, options?: { overflow?: \"constrain\" | \"reject\" }): TemporalPlainDateTimeLike;\n\t};\n}\n\n/** What {@link createTemporalCalendar} takes beside the implementation. */\nexport interface TemporalCalendarOptions {\n\t/**\n\t * The IANA time zone the engine computes dates in (`\"Asia/Tokyo\"`,\n\t * `\"UTC\"`). Defaults to the runtime's own zone, `Temporal.Now.timeZoneId()`,\n\t * which is what the `Date` backend reads. A zone the implementation does\n\t * not know is refused at construction with `TEMPORAL_TIME_ZONE_UNKNOWN`.\n\t */\n\ttimeZone?: string;\n\t/**\n\t * The clock `now()` reads, in epoch milliseconds. Defaults to\n\t * `Temporal.Now.instant()`. A test pins a date with this: a fake-timer\n\t * library replaces `Date.now`, which the `Date` backend reads, but not\n\t * `Temporal.Now`, so this backend needs telling separately.\n\t */\n\tnow?: () => number;\n}\n\n/** The fields the `Date` backend answers for an instant it cannot represent. */\nconst NAN_FIELDS: CalendarFields = Object.freeze({\n\tyear: Number.NaN, month0: Number.NaN, day: Number.NaN, weekday: Number.NaN,\n\thour: Number.NaN, minute: Number.NaN, second: Number.NaN, millisecond: Number.NaN,\n});\n\n/** The largest magnitude `Date` represents, in milliseconds either side of the epoch. */\nconst MAX_INSTANT = 8.64e15;\n\n/** Milliseconds in a day of wall-clock fields, before any zone is consulted. */\nconst MS_PER_DAY = 86_400_000;\n\n/**\n * An instant as `Date` would hold it: truncated to a whole millisecond, or\n * `NaN` when it is not finite or lies past the range `Date` represents. This\n * is `Date`'s own clip (its `TimeClip`), applied before an instant reaches\n * `Temporal`, which throws for both cases where `Date` answers `NaN`.\n */\nfunction clip(epochMs: number): number {\n\tif (!Number.isFinite(epochMs) || Math.abs(epochMs) > MAX_INSTANT) return Number.NaN;\n\treturn Math.trunc(epochMs);\n}\n\n/**\n * Wall-clock fields normalised the way `Date`'s `MakeDay` and `MakeTime`\n * normalise them, with nothing clipped: the day number of the date the\n * fields land on after any overflow rolls, and the time within that day.\n * Each field is truncated to an integer first, as `Date` truncates it.\n */\ninterface WallClock {\n\treadonly dayNumber: number;\n\treadonly timeOfDay: number;\n}\n\n/** `MakeDay` and `MakeTime`, then `MakeDate`, with a time past midnight carried into the day. */\nfunction normaliseWallClock(year: number, month0: number, day: number, hour: number, minute: number, second: number, millisecond: number): WallClock {\n\tconst time = Math.trunc(hour) * 3_600_000 + Math.trunc(minute) * 60_000 + Math.trunc(second) * 1_000 + Math.trunc(millisecond);\n\tconst dayNumber = civilDayNumber(year, month0, day) + Math.floor(time / MS_PER_DAY);\n\treturn { dayNumber, timeOfDay: ((time % MS_PER_DAY) + MS_PER_DAY) % MS_PER_DAY };\n}\n\n/**\n * The ECMAScript date-time string format, as the `Date` constructor reads it:\n * a four-digit or six-digit signed year, an optional month and day, an\n * optional time to the millisecond (longer fractions are truncated), and an\n * optional `Z` or offset. The `T` and `Z` may be lower case, and an offset\n * may omit its colon; both are what the runtime's parser accepts.\n */\nconst ISO_DATE_TIME =\n\t/^([+-]\\d{6}|\\d{4})(?:-(\\d{2})(?:-(\\d{2}))?)?(?:[Tt](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?)?([Zz]|[+-]\\d{2}:?\\d{2})?$/;\n\n/**\n * A {@link CalendarBackend} over a `Temporal` implementation, computing in\n * one named time zone. Build one with {@link createTemporalCalendar}.\n *\n * Every method answers what the `Date` backend answers for the same inputs\n * when the zone is the process's own; see the module comment for the\n * differences between `Temporal` and `Date` that are reproduced deliberately.\n * The local methods answer `NaN` for an instant or a date the backend cannot\n * represent and never throw; the four named-zone methods throw the runtime's\n * `RangeError` for a zone it does not know or an instant it cannot represent,\n * which is the contract the interface states.\n */\nexport class TemporalCalendar implements CalendarBackend {\n\t/** The IANA zone every local answer is computed in, in its canonical spelling. */\n\treadonly timeZone: string;\n\n\tprivate readonly temporal: TemporalLike;\n\tprivate readonly clock: () => number;\n\n\tconstructor(temporal: TemporalLike, options: TemporalCalendarOptions = {}) {\n\t\tassertTemporalLike(temporal);\n\t\tthis.temporal = temporal;\n\t\tconst requested = options.timeZone ?? temporal.Now.timeZoneId();\n\t\tlet probe: TemporalZonedDateTimeLike;\n\t\ttry {\n\t\t\tprobe = temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(requested);\n\t\t} catch (error) {\n\t\t\tthrow ErrorFactory.config(\n\t\t\t\tCoreErrorCodes.TEMPORAL_TIME_ZONE_UNKNOWN,\n\t\t\t\t`The Temporal implementation does not know the time zone \"${requested}\"`,\n\t\t\t\t{ timeZone: requested, cause: error instanceof Error ? error.message : String(error) },\n\t\t\t);\n\t\t}\n\t\t// The canonical spelling, so a zone given as `asia/tokyo` reads back as\n\t\t// the identifier the implementation itself uses.\n\t\tthis.timeZone = probe.timeZoneId;\n\t\tthis.clock = options.now ?? (() => temporal.Now.instant().epochMilliseconds);\n\t}\n\n\tnow(): number {\n\t\treturn this.clock();\n\t}\n\n\tfields(epochMs: number): CalendarFields {\n\t\tconst z = this.zoned(epochMs, this.timeZone);\n\t\tif (z === null) return NAN_FIELDS;\n\t\treturn {\n\t\t\tyear: z.year,\n\t\t\tmonth0: z.month - 1,\n\t\t\tday: z.day,\n\t\t\t// ISO's Monday 1 to Sunday 7 becomes Date's Sunday 0 to Saturday 6.\n\t\t\tweekday: z.dayOfWeek % 7,\n\t\t\thour: z.hour,\n\t\t\tminute: z.minute,\n\t\t\tsecond: z.second,\n\t\t\tmillisecond: z.millisecond,\n\t\t};\n\t}\n\n\tlocalMidnight(year: number, month0: number, day: number): number {\n\t\treturn this.wallClock(year, month0, day, 0, 0, 0, 0);\n\t}\n\n\tlocalWallClock(year: number, month0: number, day: number, minutesPastMidnight: number): number {\n\t\t// `Date`'s sequence exactly: anchor at midnight, then set the minutes\n\t\t// FIELD, which reads the hour, second and millisecond back from the\n\t\t// anchored local time. On a day whose midnight falls in a\n\t\t// daylight-saving gap the anchor resolves to 1 am, and the hour it\n\t\t// reads back is 1, which is what makes the two backends agree there.\n\t\tconst anchored = this.localMidnight(year, month0, day);\n\t\tconst a = this.fields(anchored);\n\t\tif (Number.isNaN(a.year)) return Number.NaN;\n\t\treturn this.wallClock(a.year, a.month0, a.day, a.hour, minutesPastMidnight, a.second, a.millisecond);\n\t}\n\n\taddDays(epochMs: number, days: number): number {\n\t\t// `setDate()`: the day field moves and the local time of day is held.\n\t\tconst f = this.fields(epochMs);\n\t\tif (Number.isNaN(f.year)) return Number.NaN;\n\t\treturn this.wallClock(f.year, f.month0, f.day + days, f.hour, f.minute, f.second, f.millisecond);\n\t}\n\n\taddMonths(epochMs: number, months: number): number {\n\t\t// The `Date` backend's three field writes, each resolved to an instant\n\t\t// and read back before the next, so that a wall-clock time landing in\n\t\t// a transition on an intermediate date shifts the same way it does\n\t\t// there: park on the 1st, move the month, then clamp the day.\n\t\tconst f0 = this.fields(epochMs);\n\t\tif (Number.isNaN(f0.year)) return Number.NaN;\n\t\tconst dayOfMonth = f0.day;\n\t\tconst f1 = this.fields(this.wallClock(f0.year, f0.month0, 1, f0.hour, f0.minute, f0.second, f0.millisecond));\n\t\tif (Number.isNaN(f1.year)) return Number.NaN;\n\t\tconst f2 = this.fields(this.wallClock(f1.year, f1.month0 + months, f1.day, f1.hour, f1.minute, f1.second, f1.millisecond));\n\t\tif (Number.isNaN(f2.year)) return Number.NaN;\n\t\tconst day = Math.min(dayOfMonth, daysInMonth(f2.year, f2.month0));\n\t\treturn this.wallClock(f2.year, f2.month0, day, f2.hour, f2.minute, f2.second, f2.millisecond);\n\t}\n\n\tutcOffsetMinutes(epochMs: number): number {\n\t\tconst z = this.zoned(epochMs, this.timeZone);\n\t\tif (z === null) return Number.NaN;\n\t\t// `getTimezoneOffset()` answers whole minutes, truncated toward zero,\n\t\t// which only shows for the local-mean-time offsets in force before a\n\t\t// zone adopted standard time (London's was -00:01:15 until 1847).\n\t\t// `|| 0` folds the -0 a small negative offset truncates to.\n\t\treturn Math.trunc(z.offsetNanoseconds / 60_000_000_000) || 0;\n\t}\n\n\tparseIso8601(text: string): number {\n\t\t// Only the format itself. The `Date` constructor falls back to a\n\t\t// legacy parser for a string the format rejects (one with a space\n\t\t// around it, say) and may guess an instant from it; the engine's own\n\t\t// gate admits only the format, so the two backends cannot disagree\n\t\t// through it, and outside it this backend answers NaN rather than guess.\n\t\tconst m = ISO_DATE_TIME.exec(text);\n\t\tif (m === null) return Number.NaN;\n\t\tconst [, yearText, monthText, dayText, hourText, minuteText, secondText, fractionText, zoneText] = m;\n\t\t// An expanded year of `-000000` names no year, by the format's own rule.\n\t\tif (yearText === \"-000000\") return Number.NaN;\n\t\tconst year = Number(yearText);\n\t\tconst month = monthText === undefined ? 1 : Number(monthText);\n\t\tconst day = dayText === undefined ? 1 : Number(dayText);\n\t\tconst hour = hourText === undefined ? 0 : Number(hourText);\n\t\tconst minute = minuteText === undefined ? 0 : Number(minuteText);\n\t\tconst second = secondText === undefined ? 0 : Number(secondText);\n\t\t// Only the first three digits of a fraction are milliseconds; the rest\n\t\t// are dropped rather than rounded, as the runtime's parser does.\n\t\tconst millisecond = fractionText === undefined ? 0 : Number(fractionText.slice(0, 3).padEnd(3, \"0\"));\n\t\t// The runtime checks a day against 31, not against the month, and lets\n\t\t// 30 February roll into March; 24:00 is the end of the day and nothing\n\t\t// past it is a time.\n\t\tif (month < 1 || month > 12 || day < 1 || day > 31) return Number.NaN;\n\t\tif (hour > 24 || minute > 59 || second > 59) return Number.NaN;\n\t\tif (hour === 24 && (minute !== 0 || second !== 0 || millisecond !== 0)) return Number.NaN;\n\n\t\t// The year is taken literally: the format has no 1900s window for a\n\t\t// year from 0 to 99, unlike the constructor.\n\t\tconst wall = normaliseWallClock(year, month - 1, day, hour, minute, second, millisecond);\n\t\tif (zoneText === undefined && hourText !== undefined) {\n\t\t\t// A date-time with no offset is local time, by the format's own rule.\n\t\t\treturn this.resolve(wall);\n\t\t}\n\t\t// A date-only string is UTC midnight, and an offset is subtracted.\n\t\tlet offsetMinutes = 0;\n\t\tif (zoneText !== undefined && zoneText !== \"Z\" && zoneText !== \"z\") {\n\t\t\tconst digits = zoneText.slice(1).replace(\":\", \"\");\n\t\t\tconst offsetHours = Number(digits.slice(0, 2));\n\t\t\tconst offsetMinutesPart = Number(digits.slice(2, 4));\n\t\t\tif (offsetHours > 23 || offsetMinutesPart > 59) return Number.NaN;\n\t\t\toffsetMinutes = (zoneText[0] === \"-\" ? -1 : 1) * (offsetHours * 60 + offsetMinutesPart);\n\t\t}\n\t\tconst instant = wall.dayNumber * MS_PER_DAY + wall.timeOfDay - offsetMinutes * 60_000;\n\t\treturn Math.abs(instant) > MAX_INSTANT ? Number.NaN : instant;\n\t}\n\n\tformatLongDate(epochMs: number, locale: string): string {\n\t\tconst t = clip(epochMs);\n\t\t// `toLocaleDateString()` on an invalid date, rather than the throw\n\t\t// `Intl` would raise.\n\t\tif (Number.isNaN(t)) return \"Invalid Date\";\n\t\treturn new Intl.DateTimeFormat(locale, {\n\t\t\ttimeZone: this.timeZone, weekday: \"long\", year: \"numeric\", month: \"long\", day: \"numeric\",\n\t\t}).format(t);\n\t}\n\n\tformatTimeOfDay(epochMs: number, locale: string): string {\n\t\tconst t = clip(epochMs);\n\t\tif (Number.isNaN(t)) return \"Invalid Date\";\n\t\t// `toLocaleTimeString()` with no options is the hour, minute and second\n\t\t// in the locale's own style.\n\t\treturn new Intl.DateTimeFormat(locale, {\n\t\t\ttimeZone: this.timeZone, hour: \"numeric\", minute: \"numeric\", second: \"numeric\",\n\t\t}).format(t);\n\t}\n\n\tzoneOffsetMinutes(zone: string, epochMs: number): number {\n\t\t// A fault here is the caller's to see, as the contract states, so no\n\t\t// clip: a non-finite instant reaches `Temporal` and throws its\n\t\t// RangeError, as an unknown zone does.\n\t\tconst t = Number.isFinite(epochMs) ? Math.trunc(epochMs) : epochMs;\n\t\tconst z = this.temporal.Instant.fromEpochMilliseconds(t).toZonedDateTimeISO(zone);\n\t\t// The `Date` backend reads the zone's wall clock to the second and\n\t\t// rounds the difference from the instant to whole minutes; the same\n\t\t// arithmetic on the exact offset keeps the two answers identical for\n\t\t// the pre-standard-time offsets that are not whole minutes.\n\t\tconst wallSecond = Math.floor((t + z.offsetNanoseconds / 1e6) / 1000) * 1000;\n\t\treturn Math.round((wallSecond - epochMs) / 60_000) || 0;\n\t}\n\n\tfieldsInZone(zone: string, epochMs: number): ZonedFields {\n\t\tconst t = Number.isFinite(epochMs) ? Math.trunc(epochMs) : epochMs;\n\t\tconst z = this.temporal.Instant.fromEpochMilliseconds(t).toZonedDateTimeISO(zone);\n\t\treturn { year: z.year, month0: z.month - 1, day: z.day, hour: z.hour, minute: z.minute, second: z.second };\n\t}\n\n\t/** The IANA zone this backend computes in, which is what `CalendarBackend.zone` documents. */\n\tzone(): string {\n\t\treturn this.timeZone;\n\t}\n\n\tformatTimeInZone(zone: string, epochMs: number): string {\n\t\treturn timeInZone(zone, epochMs);\n\t}\n\n\tformatDateInZone(zone: string, epochMs: number): string {\n\t\treturn dateInZone(zone, epochMs);\n\t}\n\n\t/** The zoned date-time of an instant, or `null` where `Date` would answer `NaN`. */\n\tprivate zoned(epochMs: number, zone: string): TemporalZonedDateTimeLike | null {\n\t\tconst t = clip(epochMs);\n\t\tif (Number.isNaN(t)) return null;\n\t\ttry {\n\t\t\treturn this.temporal.Instant.fromEpochMilliseconds(t).toZonedDateTimeISO(zone);\n\t\t} catch {\n\t\t\t// Past the range the implementation represents in this zone.\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * The instant a set of local wall-clock fields names, with the fields\n\t * normalised the way `Date`'s constructor and setters normalise them\n\t * (month 12 is next January, day 0 the last of the month before, a year\n\t * from 0 to 99 the 1900s) before the zone is consulted.\n\t */\n\tprivate wallClock(year: number, month0: number, day: number, hour: number, minute: number, second: number, millisecond: number): number {\n\t\t// The constructor's two-digit-year window, applied to the year as\n\t\t// written and before any overflow, as `Date` applies it.\n\t\tconst windowed = year >= 0 && year <= 99 ? 1900 + Math.trunc(year) : year;\n\t\treturn this.resolve(normaliseWallClock(windowed, month0, day, hour, minute, second, millisecond));\n\t}\n\n\t/**\n\t * Normalised wall-clock fields resolved to an instant in the backend's\n\t * zone, clipped to the range `Date` represents only then, as `Date` clips\n\t * last. `compatible` disambiguation is `Date`'s rule: a time in a\n\t * spring-forward gap moves later by the gap, and a time that occurs twice\n\t * on a fall-back day is its first occurrence.\n\t */\n\tprivate resolve(wall: WallClock): number {\n\t\tconst civil = civilFromDayNumber(wall.dayNumber);\n\t\tif (Number.isNaN(civil.year)) return Number.NaN;\n\t\tconst hour = Math.floor(wall.timeOfDay / 3_600_000);\n\t\tconst minute = Math.floor(wall.timeOfDay / 60_000) % 60;\n\t\tconst second = Math.floor(wall.timeOfDay / 1_000) % 60;\n\t\tconst millisecond = wall.timeOfDay % 1_000;\n\t\ttry {\n\t\t\tconst plain = this.temporal.PlainDateTime.from(\n\t\t\t\t{ year: civil.year, month: civil.month0 + 1, day: civil.day, hour, minute, second, millisecond },\n\t\t\t\t{ overflow: \"reject\" },\n\t\t\t);\n\t\t\tconst instant = plain.toZonedDateTime(this.timeZone, { disambiguation: \"compatible\" }).epochMilliseconds;\n\t\t\treturn Math.abs(instant) > MAX_INSTANT ? Number.NaN : instant;\n\t\t} catch {\n\t\t\t// Past the range the implementation represents: `Date` answers NaN.\n\t\t\treturn Number.NaN;\n\t\t}\n\t}\n}\n\n/** Refuse anything that is not a usable `Temporal` before a method can fail on it obscurely. */\nfunction assertTemporalLike(temporal: unknown): asserts temporal is TemporalLike {\n\tconst candidate = temporal as Partial<TemporalLike> | null | undefined;\n\tconst missing =\n\t\ttypeof candidate?.Now?.instant !== \"function\" ? \"Now.instant\" :\n\t\ttypeof candidate?.Now?.timeZoneId !== \"function\" ? \"Now.timeZoneId\" :\n\t\ttypeof candidate?.Instant?.fromEpochMilliseconds !== \"function\" ? \"Instant.fromEpochMilliseconds\" :\n\t\ttypeof candidate?.PlainDateTime?.from !== \"function\" ? \"PlainDateTime.from\" :\n\t\tnull;\n\tif (missing !== null) {\n\t\tthrow ErrorFactory.config(\n\t\t\tCoreErrorCodes.TEMPORAL_IMPLEMENTATION_INVALID,\n\t\t\t`createTemporalCalendar needs a Temporal implementation (globalThis.Temporal on a runtime that ships it, or a polyfill's export); the value given has no ${missing}`,\n\t\t\t{ missing },\n\t\t);\n\t}\n}\n\n/**\n * A calendar backend over the host's `Temporal`, for the engine's `calendar`\n * option.\n *\n * ```ts\n * import { createEngine } from \"solve-engine\";\n * import { createTemporalCalendar } from \"solve-engine/temporal\";\n *\n * const calendar = createTemporalCalendar(globalThis.Temporal, { timeZone: \"Asia/Tokyo\" });\n * const engine = createEngine({ calendar });\n * ```\n *\n * @param temporal - The `Temporal` implementation: `globalThis.Temporal` where the runtime ships one, or a polyfill's export.\n * @param options - The zone to compute in and, for a test, the clock to read; see {@link TemporalCalendarOptions}.\n * @returns A backend that computes every date in that zone and answers what the `Date` backend would in it.\n * @throws `TEMPORAL_IMPLEMENTATION_INVALID` when `temporal` lacks the members the backend uses, and\n * `TEMPORAL_TIME_ZONE_UNKNOWN` when the implementation does not know the zone asked for.\n */\nexport function createTemporalCalendar(temporal: TemporalLike, options: TemporalCalendarOptions = {}): TemporalCalendar {\n\treturn new TemporalCalendar(temporal, options);\n}\n"]}