likec4 1.55.1 → 1.57.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 (244) hide show
  1. package/__app__/chunks/AIChat2.mjs +2 -0
  2. package/__app__/chunks/DiagramActorProvider.mjs +10 -0
  3. package/__app__/chunks/EmbedPage.mjs +1 -0
  4. package/__app__/chunks/ExportPage.mjs +2 -0
  5. package/__app__/chunks/LikeC4Diagram.mjs +19 -0
  6. package/__app__/chunks/LikeC4Styles.mjs +48 -0
  7. package/__app__/chunks/Markdown.mjs +1 -0
  8. package/__app__/chunks/NavigationPanel.mjs +1 -0
  9. package/__app__/chunks/ViewReact.mjs +1 -0
  10. package/__app__/chunks/adhoc-editor.mjs +1 -0
  11. package/__app__/chunks/aichat.mjs +1 -0
  12. package/__app__/chunks/box.mjs +1 -0
  13. package/__app__/chunks/create-style-context.mjs +1 -0
  14. package/__app__/chunks/css.mjs +1 -0
  15. package/__app__/chunks/factory.mjs +1 -0
  16. package/__app__/chunks/hooks.mjs +1 -0
  17. package/__app__/chunks/hstack.mjs +1 -0
  18. package/__app__/chunks/libs/@dagrejs/dagre.mjs +1 -0
  19. package/__app__/chunks/libs/@floating-ui/core.mjs +1 -0
  20. package/__app__/chunks/libs/@floating-ui/dom.mjs +1 -0
  21. package/__app__/chunks/libs/@floating-ui/react.mjs +1 -0
  22. package/__app__/chunks/libs/@mantine/core.mjs +41 -0
  23. package/__app__/chunks/libs/@mantine/hooks.mjs +1 -0
  24. package/__app__/chunks/libs/@nanostores/react.mjs +1 -0
  25. package/__app__/chunks/libs/@react-hookz/web.mjs +1 -0
  26. package/__app__/chunks/libs/@tabler/icons-react.mjs +358 -0
  27. package/__app__/chunks/libs/@tanstack/ai-client.mjs +2 -0
  28. package/__app__/chunks/libs/@tanstack/ai-react-ui.mjs +1 -0
  29. package/__app__/chunks/libs/@tanstack/ai-react.mjs +1 -0
  30. package/__app__/chunks/libs/@tanstack/ai.mjs +2 -0
  31. package/__app__/chunks/libs/@tanstack/history.mjs +1 -0
  32. package/__app__/chunks/libs/@tanstack/react-router.mjs +3 -0
  33. package/__app__/chunks/libs/@tanstack/router-core.mjs +1 -0
  34. package/__app__/chunks/libs/@xstate/react.mjs +1 -0
  35. package/__app__/chunks/libs/@xstate/store.mjs +1 -0
  36. package/__app__/chunks/libs/@xyflow/react.mjs +7 -0
  37. package/__app__/chunks/libs/@zag-js/anatomy.mjs +1 -0
  38. package/__app__/chunks/libs/@zag-js/collection.mjs +1 -0
  39. package/__app__/chunks/libs/@zag-js/core.mjs +1 -0
  40. package/__app__/chunks/libs/@zag-js/react.mjs +1 -0
  41. package/__app__/chunks/libs/@zag-js/tree-view.mjs +1 -0
  42. package/__app__/chunks/libs/bezier-js.mjs +1 -0
  43. package/__app__/chunks/libs/copy-anything.mjs +1 -0
  44. package/__app__/chunks/libs/d3-path.mjs +1 -0
  45. package/__app__/chunks/libs/d3-shape.mjs +1 -0
  46. package/__app__/chunks/libs/fast-equals.mjs +1 -0
  47. package/__app__/chunks/libs/framer-motion.mjs +9 -0
  48. package/__app__/chunks/libs/html-to-image.mjs +2 -0
  49. package/__app__/chunks/libs/motion-dom.mjs +1 -0
  50. package/__app__/chunks/libs/nanostores.mjs +1 -0
  51. package/__app__/chunks/libs/react-error-boundary.mjs +1 -0
  52. package/__app__/chunks/libs/react-resizable-panels.mjs +1 -0
  53. package/__app__/chunks/libs/remeda.mjs +1 -0
  54. package/__app__/chunks/libs/superjson.mjs +1 -0
  55. package/__app__/chunks/libs/zod.mjs +64 -0
  56. package/__app__/chunks/rolldown-runtime.mjs +1 -0
  57. package/__app__/chunks/styles.css.mjs +1 -0
  58. package/__app__/chunks/txt.mjs +1 -0
  59. package/__app__/chunks/useLikeC4Project.mjs +1 -0
  60. package/__app__/codegen/react.mjs +11 -0
  61. package/__app__/codegen/webcomponent.mjs +942 -0
  62. package/__app__/src/aichat/index.mjs +1 -0
  63. package/__app__/src/fonts.css +1 -1
  64. package/__app__/src/main.mjs +45 -0
  65. package/__app__/src/pages/AdHocViewEditor.mjs +1 -0
  66. package/__app__/src/pages/EmbedPage.mjs +1 -0
  67. package/__app__/src/pages/ExportPage.mjs +1 -0
  68. package/__app__/src/pages/ProjectsOverview.mjs +1 -0
  69. package/__app__/src/pages/ViewAsD2.mjs +1 -0
  70. package/__app__/src/pages/ViewAsDot.mjs +1 -0
  71. package/__app__/src/pages/ViewAsMmd.mjs +1 -0
  72. package/__app__/src/pages/ViewAsPuml.mjs +1 -0
  73. package/__app__/src/pages/ViewEditor.mjs +1 -0
  74. package/__app__/src/pages/ViewReact.mjs +1 -0
  75. package/__app__/src/style.css +1 -1
  76. package/config/schema.json +14 -41
  77. package/dist/chunks/enableServer.mjs +1 -0
  78. package/dist/chunks/filenames.mjs +17 -0
  79. package/dist/{_chunks → chunks}/index.d.mts +2 -1
  80. package/dist/{_chunks → chunks}/index2.d.mts +639 -388
  81. package/dist/chunks/libs/@chevrotain/gast.mjs +1 -0
  82. package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -0
  83. package/dist/chunks/libs/@chevrotain/utils.mjs +1 -0
  84. package/dist/chunks/libs/@hono/mcp.mjs +70 -0
  85. package/dist/chunks/libs/@hono/node-server.mjs +1 -0
  86. package/dist/{_chunks → chunks}/libs/@logtape/logtape.d.mts +2 -0
  87. package/dist/chunks/libs/@logtape/logtape.mjs +4 -0
  88. package/dist/chunks/libs/@lume/kiwi.mjs +1 -0
  89. package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +12 -0
  90. package/dist/chunks/libs/@ts-graphviz/ast.mjs +3 -0
  91. package/dist/chunks/libs/@ts-graphviz/common.d.mts +9 -0
  92. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -0
  93. package/dist/chunks/libs/ajv.mjs +1 -0
  94. package/dist/chunks/libs/ansi-align.mjs +2 -0
  95. package/dist/chunks/libs/ansi-regex.mjs +1 -0
  96. package/dist/chunks/libs/ansi-styles.mjs +1 -0
  97. package/dist/chunks/libs/atomically.mjs +1 -0
  98. package/dist/chunks/libs/birpc.mjs +1 -0
  99. package/dist/chunks/libs/boxen.mjs +22 -0
  100. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -0
  101. package/dist/chunks/libs/chevrotain.mjs +58 -0
  102. package/dist/chunks/libs/conf.mjs +1 -0
  103. package/dist/chunks/libs/defu.mjs +1 -0
  104. package/dist/chunks/libs/destr.mjs +1 -0
  105. package/dist/chunks/libs/eventemitter3.mjs +1 -0
  106. package/dist/chunks/libs/find-up-simple.mjs +1 -0
  107. package/dist/chunks/libs/get-port.mjs +1 -0
  108. package/dist/chunks/libs/hono.mjs +1 -0
  109. package/dist/chunks/libs/is-docker.mjs +1 -0
  110. package/dist/chunks/libs/is-error-instance.mjs +1 -0
  111. package/dist/chunks/libs/is-inside-container.mjs +1 -0
  112. package/dist/chunks/libs/is-plain-obj.mjs +1 -0
  113. package/dist/chunks/libs/isexe.mjs +1 -0
  114. package/dist/chunks/libs/json5.mjs +14 -0
  115. package/dist/chunks/libs/khroma.mjs +1 -0
  116. package/dist/chunks/libs/ky.mjs +3 -0
  117. package/dist/{_chunks → chunks}/libs/langium.d.mts +9 -9
  118. package/dist/chunks/libs/langium.mjs +32 -0
  119. package/dist/chunks/libs/merge-error-cause.mjs +2 -0
  120. package/dist/chunks/libs/p-debounce.mjs +1 -0
  121. package/dist/chunks/libs/p-limit.mjs +1 -0
  122. package/dist/chunks/libs/p-queue.mjs +1 -0
  123. package/dist/chunks/libs/p-timeout.mjs +1 -0
  124. package/dist/chunks/libs/package-manager-detector.mjs +1 -0
  125. package/dist/chunks/libs/package-up.mjs +1 -0
  126. package/dist/chunks/libs/pako.mjs +3 -0
  127. package/dist/chunks/libs/parse-ms.mjs +1 -0
  128. package/dist/chunks/libs/pathe.mjs +1 -0
  129. package/dist/chunks/libs/picomatch.mjs +1 -0
  130. package/dist/chunks/libs/pretty-ms.mjs +1 -0
  131. package/dist/chunks/libs/remeda.mjs +1 -0
  132. package/dist/chunks/libs/safe-stringify.mjs +1 -0
  133. package/dist/chunks/libs/strip-indent.mjs +1 -0
  134. package/dist/chunks/libs/tinyrainbow.mjs +1 -0
  135. package/dist/chunks/libs/ts-graphviz.mjs +1 -0
  136. package/dist/chunks/libs/ufo.mjs +1 -0
  137. package/dist/chunks/libs/unctx.mjs +1 -0
  138. package/dist/chunks/libs/unstorage.mjs +1 -0
  139. package/dist/chunks/libs/vscode-languageserver.mjs +1 -0
  140. package/dist/chunks/libs/which.mjs +1 -0
  141. package/dist/chunks/libs/word-wrap.mjs +12 -0
  142. package/dist/{_chunks → chunks}/libs/zod.d.mts +62 -25
  143. package/dist/chunks/node.mjs +93 -0
  144. package/dist/chunks/plugin.mjs +593 -0
  145. package/dist/chunks/rolldown-runtime.mjs +1 -0
  146. package/dist/chunks/sequence-view.mjs +1 -0
  147. package/dist/cli/index.mjs +188 -59
  148. package/dist/config/index.d.mts +1 -2
  149. package/dist/config/index.mjs +1 -1
  150. package/dist/index.d.mts +2 -135
  151. package/dist/index.mjs +1 -1
  152. package/dist/model/index.d.mts +3 -2
  153. package/dist/model/index.mjs +1 -1
  154. package/dist/vite-plugin/index.d.mts +90 -9
  155. package/dist/vite-plugin/index.mjs +1 -1
  156. package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.mjs +1 -0
  157. package/dist/vite-plugin/internal/chunks/libs/birpc.mjs +1 -0
  158. package/dist/vite-plugin/internal/chunks/libs/fast-equals.mjs +1 -0
  159. package/dist/vite-plugin/internal/chunks/libs/nanostores.mjs +1 -0
  160. package/dist/vite-plugin/internal/chunks/libs/remeda.mjs +1 -0
  161. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +1 -0
  162. package/dist/{_chunks/libs/@nanostores/react.d.mts → vite-plugin/internal/index.d.mts} +103 -45
  163. package/dist/vite-plugin/internal/index.mjs +1 -0
  164. package/package.json +74 -80
  165. package/react/index.d.mts +84 -78
  166. package/react/index.mjs +51954 -53701
  167. package/vite-plugin/internal/package.json +2 -2
  168. package/vite-plugin-modules.d.ts +18 -0
  169. package/__app__/react/likec4.tsx +0 -25
  170. package/__app__/src/ProjectsOverview.js +0 -16
  171. package/__app__/src/const.js +0 -19
  172. package/__app__/src/likec4.js +0 -21254
  173. package/__app__/src/main.js +0 -7
  174. package/__app__/src/routes/index.js +0 -324
  175. package/__app__/src/routes/projects.js +0 -193
  176. package/__app__/src/routes/single.js +0 -1983
  177. package/__app__/src/vendors.js +0 -52683
  178. package/__app__/src/webcomponent.js +0 -68
  179. package/dist/THIRD-PARTY-LICENSES.md +0 -1609
  180. package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +0 -30
  181. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +0 -9
  182. package/dist/_chunks/libs/@chevrotain/types.d.mts +0 -1
  183. package/dist/_chunks/libs/@chevrotain/utils.mjs +0 -1
  184. package/dist/_chunks/libs/@hono/mcp.mjs +0 -45
  185. package/dist/_chunks/libs/@hono/node-server.mjs +0 -1
  186. package/dist/_chunks/libs/@logtape/logtape.mjs +0 -4
  187. package/dist/_chunks/libs/@lume/kiwi.mjs +0 -1
  188. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +0 -12
  189. package/dist/_chunks/libs/@nanostores/react.mjs +0 -1
  190. package/dist/_chunks/libs/ajv.mjs +0 -1
  191. package/dist/_chunks/libs/ansi-align.mjs +0 -2
  192. package/dist/_chunks/libs/ansi-regex.mjs +0 -1
  193. package/dist/_chunks/libs/ansi-styles.mjs +0 -1
  194. package/dist/_chunks/libs/atomically.mjs +0 -1
  195. package/dist/_chunks/libs/birpc.mjs +0 -1
  196. package/dist/_chunks/libs/boxen.mjs +0 -22
  197. package/dist/_chunks/libs/chevrotain-allstar.mjs +0 -2
  198. package/dist/_chunks/libs/chevrotain.mjs +0 -58
  199. package/dist/_chunks/libs/conf.mjs +0 -1
  200. package/dist/_chunks/libs/defu.mjs +0 -1
  201. package/dist/_chunks/libs/destr.mjs +0 -1
  202. package/dist/_chunks/libs/esm-env.mjs +0 -1
  203. package/dist/_chunks/libs/eventemitter3.mjs +0 -1
  204. package/dist/_chunks/libs/fast-equals.mjs +0 -1
  205. package/dist/_chunks/libs/find-up-simple.mjs +0 -1
  206. package/dist/_chunks/libs/get-port.mjs +0 -1
  207. package/dist/_chunks/libs/is-docker.mjs +0 -1
  208. package/dist/_chunks/libs/is-error-instance.mjs +0 -1
  209. package/dist/_chunks/libs/is-inside-container.mjs +0 -1
  210. package/dist/_chunks/libs/is-plain-obj.mjs +0 -1
  211. package/dist/_chunks/libs/isexe.mjs +0 -1
  212. package/dist/_chunks/libs/json5.mjs +0 -14
  213. package/dist/_chunks/libs/khroma.mjs +0 -1
  214. package/dist/_chunks/libs/ky.mjs +0 -3
  215. package/dist/_chunks/libs/langium.mjs +0 -33
  216. package/dist/_chunks/libs/merge-error-cause.mjs +0 -2
  217. package/dist/_chunks/libs/p-limit.mjs +0 -1
  218. package/dist/_chunks/libs/p-queue.mjs +0 -1
  219. package/dist/_chunks/libs/p-timeout.mjs +0 -1
  220. package/dist/_chunks/libs/package-manager-detector.mjs +0 -1
  221. package/dist/_chunks/libs/package-up.mjs +0 -1
  222. package/dist/_chunks/libs/pako.mjs +0 -1
  223. package/dist/_chunks/libs/parse-ms.mjs +0 -1
  224. package/dist/_chunks/libs/pathe.mjs +0 -1
  225. package/dist/_chunks/libs/picomatch.mjs +0 -1
  226. package/dist/_chunks/libs/pretty-ms.mjs +0 -1
  227. package/dist/_chunks/libs/remeda.mjs +0 -2
  228. package/dist/_chunks/libs/safe-stringify.mjs +0 -1
  229. package/dist/_chunks/libs/strip-indent.mjs +0 -1
  230. package/dist/_chunks/libs/tinyrainbow.mjs +0 -1
  231. package/dist/_chunks/libs/ts-graphviz.d.mts +0 -10
  232. package/dist/_chunks/libs/ts-graphviz.mjs +0 -4
  233. package/dist/_chunks/libs/ufo.mjs +0 -1
  234. package/dist/_chunks/libs/unstorage.mjs +0 -1
  235. package/dist/_chunks/libs/vscode-languageserver.mjs +0 -1
  236. package/dist/_chunks/libs/which.mjs +0 -1
  237. package/dist/_chunks/libs/word-wrap.mjs +0 -12
  238. package/dist/_chunks/node.mjs +0 -76
  239. package/dist/_chunks/rolldown-runtime.mjs +0 -1
  240. package/dist/_chunks/sequence.mjs +0 -1
  241. package/dist/_chunks/src.mjs +0 -17
  242. package/dist/_chunks/src2.mjs +0 -499
  243. package/dist/vite-plugin/internal.d.mts +0 -44
  244. package/dist/vite-plugin/internal.mjs +0 -1
@@ -0,0 +1 @@
1
+ import"../../rolldown-runtime.mjs";import e from"node:crypto";import{createServer as t}from"node:http";import{Http2ServerRequest as n,constants as r}from"node:http2";import{Readable as i}from"node:stream";var RequestError=class extends Error{constructor(e,t){super(e,t),this.name=`RequestError`}},toRequestError=e=>e instanceof RequestError?e:new RequestError(e.message,{cause:e}),a=global.Request,Request=class extends a{constructor(e,t){typeof e==`object`&&s in e&&(e=e[s]()),t?.body?.getReader!==void 0&&(t.duplex??=`half`),super(e,t)}},newHeadersFromIncoming=e=>{let t=[],n=e.rawHeaders;for(let e=0;e<n.length;e+=2){let{[e]:r,[e+1]:i}=n;r.charCodeAt(0)!==58&&t.push([r,i])}return new Headers(t)},o=Symbol(`wrapBodyStream`),newRequestFromIncoming=(e,t,n,r,a)=>{let s={method:e,headers:n,signal:a.signal};if(e===`TRACE`){s.method=`GET`;let e=new Request(t,s);return Object.defineProperty(e,"method",{get(){return`TRACE`}}),e}if(!(e===`GET`||e===`HEAD`))if(`rawBody`in r&&r.rawBody instanceof Buffer)s.body=new ReadableStream({start(e){e.enqueue(r.rawBody),e.close()}});else if(r[o]){let e;s.body=new ReadableStream({async pull(t){try{e||=i.toWeb(r).getReader();let{done:n,value:a}=await e.read();n?t.close():t.enqueue(a)}catch(e){t.error(e)}}})}else s.body=i.toWeb(r);return new Request(t,s)},s=Symbol(`getRequestCache`),c=Symbol(`requestCache`),l=Symbol(`incomingKey`),u=Symbol(`urlKey`),d=Symbol(`headersKey`),f=Symbol(`abortControllerKey`),p={get method(){return this[l].method||`GET`},get url(){return this[u]},get headers(){return this[d]||=newHeadersFromIncoming(this[l])},[Symbol(`getAbortController`)](){return this[s](),this[f]},[s](){return this[f]||=new AbortController,this[c]||=newRequestFromIncoming(this.method,this[u],this.headers,this[l],this[f])}};[`body`,`bodyUsed`,`cache`,`credentials`,`destination`,`integrity`,`mode`,`redirect`,`referrer`,`referrerPolicy`,`signal`,`keepalive`].forEach(e=>{Object.defineProperty(p,e,{get(){return this[s]()[e]}})}),[`arrayBuffer`,`blob`,`clone`,`formData`,`json`,`text`].forEach(e=>{Object.defineProperty(p,e,{value:function(){return this[s]()[e]()}})}),Object.defineProperty(p,Symbol.for(`nodejs.util.inspect.custom`),{value:function(e,t,n){return`Request (lightweight) ${n({method:this.method,url:this.url,headers:this.headers,nativeRequest:this[c]},{...t,depth:e==null?null:e-1})}`}}),Object.setPrototypeOf(p,Request.prototype);var newRequest=(e,t)=>{let r=Object.create(p);r[l]=e;let i=e.url||``;if(i[0]!==`/`&&(i.startsWith(`http://`)||i.startsWith(`https://`))){if(e instanceof n)throw new RequestError(`Absolute URL for :path is not allowed in HTTP/2`);try{r[u]=new URL(i).href}catch(e){throw new RequestError(`Invalid absolute URL`,{cause:e})}return r}let a=(e instanceof n?e.authority:e.headers.host)||t;if(!a)throw new RequestError(`Missing host header`);let o;if(e instanceof n){if(o=e.scheme,!(o===`http`||o===`https`))throw new RequestError(`Unsupported scheme`)}else o=e.socket&&e.socket.encrypted?`https`:`http`;let s=new URL(`${o}://${a}${i}`);if(s.hostname.length!==a.length&&s.hostname!==a.replace(/:\d+$/,``))throw new RequestError(`Invalid host header`);return r[u]=s.href,r},m=Symbol(`responseCache`),h=Symbol(`getResponseCache`),g=Symbol(`cache`),_=global.Response,v=class _Response{#e;#t;[h](){return delete this[g],this[m]||=new _(this.#e,this.#t)}constructor(e,t){let n;if(this.#e=e,t instanceof _Response){let e=t[m];if(e){this.#t=e,this[h]();return}else this.#t=t.#t,n=new Headers(t.#t.headers)}else this.#t=t;(typeof e==`string`||e?.getReader!==void 0||e instanceof Blob||e instanceof Uint8Array)&&(this[g]=[t?.status||200,e,n||t?.headers])}get headers(){let e=this[g];return e?(e[2]instanceof Headers||(e[2]=new Headers(e[2]||{"content-type":`text/plain; charset=UTF-8`})),e[2]):this[h]().headers}get status(){return this[g]?.[0]??this[h]().status}get ok(){let e=this.status;return e>=200&&e<300}};[`body`,`bodyUsed`,`redirected`,`statusText`,`trailers`,`type`,`url`].forEach(e=>{Object.defineProperty(v.prototype,e,{get(){return this[h]()[e]}})}),[`arrayBuffer`,`blob`,`clone`,`formData`,`json`,`text`].forEach(e=>{Object.defineProperty(v.prototype,e,{value:function(){return this[h]()[e]()}})}),Object.defineProperty(v.prototype,Symbol.for(`nodejs.util.inspect.custom`),{value:function(e,t,n){return`Response (lightweight) ${n({status:this.status,headers:this.headers,ok:this.ok,nativeResponse:this[m]},{...t,depth:e==null?null:e-1})}`}}),Object.setPrototypeOf(v,_),Object.setPrototypeOf(v.prototype,_.prototype);async function readWithoutBlocking(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function writeFromReadableStreamDefaultReader(e,t,n){let cancel=t=>{e.cancel(t).catch(()=>{})};return t.on(`close`,cancel),t.on(`error`,cancel),(n??e.read()).then(flow,handleStreamError),e.closed.finally(()=>{t.off(`close`,cancel),t.off(`error`,cancel)});function handleStreamError(e){e&&t.destroy(e)}function onDrain(){e.read().then(flow,handleStreamError)}function flow({done:n,value:r}){try{if(n)t.end();else if(!t.write(r))t.once(`drain`,onDrain);else return e.read().then(flow,handleStreamError)}catch(e){handleStreamError(e)}}}function writeFromReadableStream(e,t){if(e.locked)throw TypeError(`ReadableStream is locked.`);return t.destroyed?void 0:writeFromReadableStreamDefaultReader(e.getReader(),t)}var buildOutgoingHttpHeaders=e=>{let t={};e instanceof Headers||(e=new Headers(e??void 0));let n=[];for(let[r,i]of e)r===`set-cookie`?n.push(i):t[r]=i;return n.length>0&&(t[`set-cookie`]=n),t[`content-type`]??=`text/plain; charset=UTF-8`,t},y=`x-hono-already-sent`;global.crypto===void 0&&(global.crypto=e);var b=Symbol(`outgoingEnded`),x=Symbol(`incomingDraining`),S=500,C=64*1024*1024,drainIncoming=e=>{let t=e;if(e.destroyed||t[x])return;if(t[x]=!0,e instanceof n){try{e.stream?.close?.(r.NGHTTP2_NO_ERROR)}catch{}return}let i=0,cleanup=()=>{clearTimeout(a),e.off(`data`,onData),e.off(`end`,cleanup),e.off(`error`,cleanup)},forceClose=()=>{cleanup();let t=e.socket;t&&!t.destroyed&&t.destroySoon()},a=setTimeout(forceClose,S);a.unref?.();let onData=e=>{i+=e.length,i>C&&forceClose()};e.on(`data`,onData),e.on(`end`,cleanup),e.on(`error`,cleanup),e.resume()},handleRequestError=()=>new Response(null,{status:400}),handleFetchError=e=>new Response(null,{status:e instanceof Error&&(e.name===`TimeoutError`||e.constructor.name===`TimeoutError`)?504:500}),handleResponseError=(e,t)=>{let n=e instanceof Error?e:Error(`unknown error`,{cause:e});n.code===`ERR_STREAM_PREMATURE_CLOSE`?console.info(`The user aborted a request.`):(console.error(e),t.headersSent||t.writeHead(500,{"Content-Type":`text/plain`}),t.end(`Error: ${n.message}`),t.destroy(n))},flushHeaders=e=>{`flushHeaders`in e&&e.writable&&e.flushHeaders()},responseViaCache=async(e,t)=>{let[n,r,i]=e[g],a=!1;if(!i)i={"content-type":`text/plain; charset=UTF-8`};else if(i instanceof Headers)a=i.has(`content-length`),i=buildOutgoingHttpHeaders(i);else if(Array.isArray(i)){let e=new Headers(i);a=e.has(`content-length`),i=buildOutgoingHttpHeaders(e)}else for(let e in i)if(e.length===14&&e.toLowerCase()===`content-length`){a=!0;break}a||(typeof r==`string`?i[`Content-Length`]=Buffer.byteLength(r):r instanceof Uint8Array?i[`Content-Length`]=r.byteLength:r instanceof Blob&&(i[`Content-Length`]=r.size)),t.writeHead(n,i),typeof r==`string`||r instanceof Uint8Array?t.end(r):r instanceof Blob?t.end(new Uint8Array(await r.arrayBuffer())):(flushHeaders(t),await writeFromReadableStream(r,t)?.catch(e=>handleResponseError(e,t))),t[b]?.()},isPromise=e=>typeof e.then==`function`,responseViaResponseObject=async(e,t,n={})=>{if(isPromise(e))if(n.errorHandler)try{e=await e}catch(t){let r=await n.errorHandler(t);if(!r)return;e=r}else e=await e.catch(handleFetchError);if(g in e)return responseViaCache(e,t);let r=buildOutgoingHttpHeaders(e.headers);if(e.body){let n=e.body.getReader(),i=[],a=!1,o;if(r[`transfer-encoding`]!==`chunked`){let e=2;for(let t=0;t<e;t++){o||=n.read();let r=await readWithoutBlocking(o).catch(e=>{console.error(e),a=!0});if(!r){if(t===1){await new Promise(e=>setTimeout(e)),e=3;continue}break}if(o=void 0,r.value&&i.push(r.value),r.done){a=!0;break}}a&&!(`content-length`in r)&&(r[`content-length`]=i.reduce((e,t)=>e+t.length,0))}t.writeHead(e.status,r),i.forEach(e=>{t.write(e)}),a?t.end():(i.length===0&&flushHeaders(t),await writeFromReadableStreamDefaultReader(n,t,o))}else r[y]||(t.writeHead(e.status,r),t.end());t[b]?.()},getRequestListener=(e,t={})=>{let r=t.autoCleanupIncoming??!0;return t.overrideGlobalObjects!==!1&&global.Request!==Request&&(Object.defineProperty(global,"Request",{value:Request}),Object.defineProperty(global,"Response",{value:v})),async(i,a)=>{let s,c;try{c=newRequest(i,t.hostname);let l=!r||i.method===`GET`||i.method===`HEAD`;if(l||(i[o]=!0,i.on(`end`,()=>{l=!0}),i instanceof n&&(a[b]=()=>{l||setTimeout(()=>{l||setTimeout(()=>{drainIncoming(i)})})}),a.on(`finish`,()=>{l||drainIncoming(i)})),a.on(`close`,()=>{c[f]&&(i.errored?c[f].abort(i.errored.toString()):a.writableFinished||c[f].abort(`Client connection prematurely closed.`)),l||setTimeout(()=>{l||setTimeout(()=>{drainIncoming(i)})})}),s=e(c,{incoming:i,outgoing:a}),g in s)return responseViaCache(s,a)}catch(e){if(s)return handleResponseError(e,a);if(t.errorHandler){if(s=await t.errorHandler(c?e:toRequestError(e)),!s)return}else s=c?handleFetchError(e):handleRequestError()}try{return await responseViaResponseObject(s,a,t)}catch(e){return handleResponseError(e,a)}}},createAdaptorServer=e=>{let n=e.fetch,r=getRequestListener(n,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||t)(e.serverOptions||{},r)},serve=(e,t)=>{let n=createAdaptorServer(e);return n.listen(e?.port??3e3,e.hostname,()=>{let e=n.address();t&&t(e)}),n};export{serve as t};
@@ -1,3 +1,5 @@
1
+ import { i as __name } from "../../rolldown-runtime.mjs";
2
+
1
3
  //#region ../../node_modules/.pnpm/@logtape+logtape@2.0.5/node_modules/@logtape/logtape/dist/level.d.ts
2
4
  //#region src/level.d.ts
3
5
  declare const logLevels: readonly ["trace", "debug", "info", "warning", "error", "fatal"];
@@ -0,0 +1,4 @@
1
+ import{i as e,r as t}from"../../rolldown-runtime.mjs";import n from"node:util";function toFilter(e){return typeof e==`function`?e:getLevelFilter(e)}function getLevelFilter(e){if(e==null)return()=>!1;if(e===`fatal`)return e=>e.level===`fatal`;if(e===`error`)return e=>e.level===`fatal`||e.level===`error`;if(e===`warning`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`;if(e===`info`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`||e.level===`info`;if(e===`debug`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`||e.level===`info`||e.level===`debug`;if(e===`trace`)return()=>!0;throw TypeError(`Invalid log level: ${e}.`)}const r=[`trace`,`debug`,`info`,`warning`,`error`,`fatal`];function compareLogLevel(e,t){let n=r.indexOf(e);if(n<0)throw TypeError(`Invalid log level: ${JSON.stringify(e)}.`);let i=r.indexOf(t);if(i<0)throw TypeError(`Invalid log level: ${JSON.stringify(t)}.`);return n-i}const i=Symbol.for(`logtape.lazy`);function isLazy(e){return typeof e==`object`&&!!e&&i in e&&e[i]===!0}function resolveProperties(e){let t={};for(let n in e){let r=e[n];t[n]=isLazy(r)?r.getter():r}return t}function getLogger(e=[]){return o.getLogger(e)}const a=Symbol.for(`logtape.rootLogger`);var o=class LoggerImpl{parent;children;category;sinks;parentSinks=`inherit`;filters;lowestLevel=`trace`;contextLocalStorage;static getLogger(e=[]){let t=a in globalThis?globalThis[a]??null:null;return t??(t=new LoggerImpl(null,[]),globalThis[a]=t),typeof e==`string`?t.getChild(e):e.length===0?t:t.getChild(e)}constructor(e,t){this.parent=e,this.children={},this.category=t,this.sinks=[],this.filters=[]}getChild(e){let t=typeof e==`string`?e:e[0],n=this.children[t],r=n instanceof LoggerImpl?n:n?.deref();return r??(r=new LoggerImpl(this,[...this.category,t]),this.children[t]=`WeakRef`in globalThis?new WeakRef(r):r),typeof e==`string`||e.length===1?r:r.getChild(e.slice(1))}reset(){for(;this.sinks.length>0;)this.sinks.shift();for(this.parentSinks=`inherit`;this.filters.length>0;)this.filters.shift();this.lowestLevel=`trace`}resetDescendants(){for(let e of Object.values(this.children))(e instanceof LoggerImpl?e:e.deref())?.resetDescendants();this.reset()}with(e){return new s(this,{...e})}filter(e){for(let t of this.filters)if(!t(e))return!1;return this.filters.length<1?this.parent?.filter(e)??!0:!0}*getSinks(e){if(!(this.lowestLevel===null||compareLogLevel(e,this.lowestLevel)<0)){if(this.parent!=null&&this.parentSinks===`inherit`)for(let t of this.parent.getSinks(e))yield t;for(let e of this.sinks)yield e}}isEnabledFor(e){if(this.lowestLevel===null||compareLogLevel(e,this.lowestLevel)<0)return!1;for(let t of this.getSinks(e))return!0;return!1}emit(e,t){let n=getCategoryPrefix(),r=`category`in e?e.category:this.category,i=n.length>0?[...n,...r]:r,a=Object.getOwnPropertyDescriptors(e);a.category={value:i,enumerable:!0,configurable:!0};let o=Object.defineProperties({},a);if(!(this.lowestLevel===null||compareLogLevel(o.level,this.lowestLevel)<0||!this.filter(o))){for(let e of this.getSinks(o.level))if(!t?.has(e))try{e(o)}catch(n){let r=new Set(t);r.add(e),c.log(`fatal`,`Failed to emit a log record to sink {sink}: {error}`,{sink:e,error:n,record:o},r)}}}log(e,t,n,r){let i=getImplicitContext(),a,o=typeof n==`function`?{category:this.category,level:e,timestamp:Date.now(),get message(){return parseMessageTemplate(t,this.properties)},rawMessage:t,get properties(){return a??={...i,...n()},a}}:{category:this.category,level:e,timestamp:Date.now(),message:parseMessageTemplate(t,{...i,...n}),rawMessage:t,properties:{...i,...n}};this.emit(o,r)}logLazily(e,t,n={}){let r=getImplicitContext(),i,a;function realizeMessage(){if((a==null||i==null)&&(a=t((e,...t)=>(i=e,renderMessage(e,t))),i==null))throw TypeError(`No log record was made.`);return[a,i]}this.emit({category:this.category,level:e,get message(){return realizeMessage()[0]},get rawMessage(){return realizeMessage()[1]},timestamp:Date.now(),properties:{...r,...n}})}logTemplate(e,t,n,r={}){let i=getImplicitContext();this.emit({category:this.category,level:e,message:renderMessage(t,n),rawMessage:t,timestamp:Date.now(),properties:{...i,...r}})}trace(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`trace`)?n().then(t=>{this.log(`trace`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`trace`)?t.then(t=>{this.log(`trace`,e,t)}):Promise.resolve();this.log(`trace`,e,t);return}this.log(`trace`,e,n??{})}else typeof e==`function`?this.logLazily(`trace`,e):Array.isArray(e)?this.logTemplate(`trace`,e,t):this.log(`trace`,`{*}`,e)}debug(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`debug`)?n().then(t=>{this.log(`debug`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`debug`)?t.then(t=>{this.log(`debug`,e,t)}):Promise.resolve();this.log(`debug`,e,t);return}this.log(`debug`,e,n??{})}else typeof e==`function`?this.logLazily(`debug`,e):Array.isArray(e)?this.logTemplate(`debug`,e,t):this.log(`debug`,`{*}`,e)}info(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`info`)?n().then(t=>{this.log(`info`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`info`)?t.then(t=>{this.log(`info`,e,t)}):Promise.resolve();this.log(`info`,e,t);return}this.log(`info`,e,n??{})}else typeof e==`function`?this.logLazily(`info`,e):Array.isArray(e)?this.logTemplate(`info`,e,t):this.log(`info`,`{*}`,e)}warn(e,...t){if(e instanceof Error)this.log(`warning`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`warning`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`warning`)?n().then(t=>{this.log(`warning`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`warning`)?t.then(t=>{this.log(`warning`,e,t)}):Promise.resolve();this.log(`warning`,e,t);return}this.log(`warning`,e,n??{})}else typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}warning(e,...t){if(e instanceof Error)this.log(`warning`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`warning`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`warning`)?n().then(t=>{this.log(`warning`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`warning`)?t.then(t=>{this.log(`warning`,e,t)}):Promise.resolve();this.log(`warning`,e,t);return}this.log(`warning`,e,n??{})}else typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}error(e,...t){if(e instanceof Error)this.log(`error`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`error`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`error`)?n().then(t=>{this.log(`error`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`error`)?t.then(t=>{this.log(`error`,e,t)}):Promise.resolve();this.log(`error`,e,t);return}this.log(`error`,e,n??{})}else typeof e==`function`?this.logLazily(`error`,e):Array.isArray(e)?this.logTemplate(`error`,e,t):this.log(`error`,`{*}`,e)}fatal(e,...t){if(e instanceof Error)this.log(`fatal`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`fatal`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`fatal`)?n().then(t=>{this.log(`fatal`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`fatal`)?t.then(t=>{this.log(`fatal`,e,t)}):Promise.resolve();this.log(`fatal`,e,t);return}this.log(`fatal`,e,n??{})}else typeof e==`function`?this.logLazily(`fatal`,e):Array.isArray(e)?this.logTemplate(`fatal`,e,t):this.log(`fatal`,`{*}`,e)}},s=class LoggerCtx{logger;properties;constructor(e,t){this.logger=e,this.properties=t}get category(){return this.logger.category}get parent(){return this.logger.parent}getChild(e){return this.logger.getChild(e).with(this.properties)}with(e){return new LoggerCtx(this.logger,{...this.properties,...e})}log(e,t,n,r){let i=this.properties;this.logger.log(e,t,typeof n==`function`?()=>resolveProperties({...i,...n()}):()=>resolveProperties({...i,...n}),r)}logLazily(e,t){this.logger.logLazily(e,t,resolveProperties(this.properties))}logTemplate(e,t,n){this.logger.logTemplate(e,t,n,resolveProperties(this.properties))}emit(e){let t={...e,properties:resolveProperties({...this.properties,...e.properties})};this.logger.emit(t)}isEnabledFor(e){return this.logger.isEnabledFor(e)}trace(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`trace`)?n().then(t=>{this.log(`trace`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`trace`)?t.then(t=>{this.log(`trace`,e,t)}):Promise.resolve();this.log(`trace`,e,t);return}this.log(`trace`,e,n??{})}else typeof e==`function`?this.logLazily(`trace`,e):Array.isArray(e)?this.logTemplate(`trace`,e,t):this.log(`trace`,`{*}`,e)}debug(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`debug`)?n().then(t=>{this.log(`debug`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`debug`)?t.then(t=>{this.log(`debug`,e,t)}):Promise.resolve();this.log(`debug`,e,t);return}this.log(`debug`,e,n??{})}else typeof e==`function`?this.logLazily(`debug`,e):Array.isArray(e)?this.logTemplate(`debug`,e,t):this.log(`debug`,`{*}`,e)}info(e,...t){if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`info`)?n().then(t=>{this.log(`info`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`info`)?t.then(t=>{this.log(`info`,e,t)}):Promise.resolve();this.log(`info`,e,t);return}this.log(`info`,e,n??{})}else typeof e==`function`?this.logLazily(`info`,e):Array.isArray(e)?this.logTemplate(`info`,e,t):this.log(`info`,`{*}`,e)}warn(e,...t){if(e instanceof Error)this.log(`warning`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`warning`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`warning`)?n().then(t=>{this.log(`warning`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`warning`)?t.then(t=>{this.log(`warning`,e,t)}):Promise.resolve();this.log(`warning`,e,t);return}this.log(`warning`,e,n??{})}else typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}warning(e,...t){if(e instanceof Error)this.log(`warning`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`warning`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`warning`)?n().then(t=>{this.log(`warning`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`warning`)?t.then(t=>{this.log(`warning`,e,t)}):Promise.resolve();this.log(`warning`,e,t);return}this.log(`warning`,e,n??{})}else typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}error(e,...t){if(e instanceof Error)this.log(`error`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`error`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`error`)?n().then(t=>{this.log(`error`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`error`)?t.then(t=>{this.log(`error`,e,t)}):Promise.resolve();this.log(`error`,e,t);return}this.log(`error`,e,n??{})}else typeof e==`function`?this.logLazily(`error`,e):Array.isArray(e)?this.logTemplate(`error`,e,t):this.log(`error`,`{*}`,e)}fatal(e,...t){if(e instanceof Error)this.log(`fatal`,`{error.message}`,{error:e});else if(typeof e==`string`&&t[0]instanceof Error)this.log(`fatal`,e,{error:t[0]});else if(typeof e==`string`){let n=t[0];if(typeof n==`function`){if(n.constructor.name===`AsyncFunction`)return this.isEnabledFor(`fatal`)?n().then(t=>{this.log(`fatal`,e,t)}):Promise.resolve();let t=n();if(t instanceof Promise)return this.isEnabledFor(`fatal`)?t.then(t=>{this.log(`fatal`,e,t)}):Promise.resolve();this.log(`fatal`,e,t);return}this.log(`fatal`,e,n??{})}else typeof e==`function`?this.logLazily(`fatal`,e):Array.isArray(e)?this.logTemplate(`fatal`,e,t):this.log(`fatal`,`{*}`,e)}};const c=o.getLogger([`logtape`,`meta`]);function isNestedAccess(e){return e.includes(`.`)||e.includes(`[`)||e.includes(`?.`)}function getOwnProperty(e,t){if(!(t===`__proto__`||t===`prototype`||t===`constructor`)&&(typeof e==`object`||typeof e==`function`)&&e!==null)return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function parseNextSegment(e,t){let n=e.length,r=t;if(r>=n)return null;let i;if(e[r]===`[`){if(r++,r>=n)return null;if(e[r]===`"`||e[r]===`'`){let t=e[r];r++;let a=``;for(;r<n&&e[r]!==t;)if(e[r]===`\\`){if(r++,r<n){let t=e[r];switch(t){case`n`:a+=`
2
+ `;break;case`t`:a+=` `;break;case`r`:a+=`\r`;break;case`b`:a+=`\b`;break;case`f`:a+=`\f`;break;case`v`:a+=`\v`;break;case`0`:a+=`\0`;break;case`\\`:a+=`\\`;break;case`"`:a+=`"`;break;case`'`:a+=`'`;break;case`u`:if(r+4<n){let n=e.slice(r+1,r+5),i=Number.parseInt(n,16);Number.isNaN(i)?a+=t:(a+=String.fromCharCode(i),r+=4)}else a+=t;break;default:a+=t}r++}}else a+=e[r],r++;if(r>=n)return null;i=a,r++}else{let t=r;for(;r<n&&e[r]!==`]`&&e[r]!==`'`&&e[r]!==`"`;)r++;if(r>=n)return null;let a=e.slice(t,r);if(a.length===0)return null;let o=Number(a);i=Number.isNaN(o)?a:o}for(;r<n&&e[r]!==`]`;)r++;r<n&&r++}else{let t=r;for(;r<n&&e[r]!==`.`&&e[r]!==`[`&&e[r]!==`?`&&e[r]!==`]`;)r++;if(i=e.slice(t,r),i.length===0)return null}return r<n&&e[r]===`.`&&r++,{segment:i,nextIndex:r}}function accessProperty(e,t){if(typeof t==`string`)return getOwnProperty(e,t);if(Array.isArray(e)&&t>=0&&t<e.length)return e[t]}function resolvePropertyPath(e,t){if(e==null||t.length===0||t.endsWith(`.`))return;let n=e,r=0,i=t.length;for(;r<i;){if(t.slice(r,r+2)===`?.`){if(r+=2,n==null)return}else if(n==null)return;let e=parseNextSegment(t,r);if(e===null)return;let{segment:i,nextIndex:a}=e;if(r=a,n=accessProperty(n,i),n===void 0)return}return n}function parseMessageTemplate(e,t){let n=e.length;if(n===0)return[``];if(!e.includes(`{`))return[e];let r=[],i=0;for(let a=0;a<n;a++){let o=e[a];if(o===`{`){if((a+1<n?e[a+1]:``)===`{`){a++;continue}let o=e.indexOf(`}`,a+1);if(o===-1)continue;let s=e.slice(i,a);r.push(s.replace(/{{/g,`{`).replace(/}}/g,`}`));let c=e.slice(a+1,o),l,u=c.trim();u===`*`?l=c in t?t[c]:`*`in t?t[`*`]:t:(l=c===u||c in t?t[c]:t[u],l===void 0&&isNestedAccess(u)&&(l=resolvePropertyPath(t,u))),r.push(l),a=o,i=a+1}else o===`}`&&a+1<n&&e[a+1]===`}`&&a++}let a=e.slice(i);return r.push(a.replace(/{{/g,`{`).replace(/}}/g,`}`)),r}function renderMessage(e,t){let n=[];for(let r=0;r<e.length;r++)n.push(e[r]),r<t.length&&n.push(t[r]);return n}const l=Symbol.for(`logtape.categoryPrefix`);function getCategoryPrefix(){let e=o.getLogger().contextLocalStorage?.getStore();if(e==null)return[];let t=e[l];return Array.isArray(t)?t:[]}function getImplicitContext(){let e=o.getLogger().contextLocalStorage?.getStore();if(e==null)return{};let t={};for(let n of Object.keys(e))t[n]=e[n];return t}var u=t({inspect:()=>inspect$1});function inspect$1(e,t){return n.inspect(e,t)}e(inspect$1,`inspect`);const d={trace:`TRC`,debug:`DBG`,info:`INF`,warning:`WRN`,error:`ERR`,fatal:`FTL`},f=typeof document<`u`||typeof navigator<`u`&&navigator.product===`ReactNative`?e=>JSON.stringify(e):`Deno`in globalThis&&`inspect`in globalThis.Deno&&typeof globalThis.Deno.inspect==`function`?(e,t)=>globalThis.Deno.inspect(e,{strAbbreviateSize:1/0,iterableLimit:1/0,...t}):u!=null&&`inspect`in u&&typeof inspect$1==`function`?(e,t)=>inspect$1(e,{maxArrayLength:1/0,maxStringLength:1/0,...t}):e=>JSON.stringify(e);function padZero(e){return e<10?`0${e}`:`${e}`}function padThree(e){return e<10?`00${e}`:e<100?`0${e}`:`${e}`}const p={"date-time-timezone":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00:00`},"date-time-tz":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00`},"date-time":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())}`},"time-timezone":e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00:00`},"time-tz":e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00`},time:e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())}`},date:e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())}`},rfc3339:e=>new Date(e).toISOString(),none:()=>null},m={ABBR:d,abbr:{trace:`trc`,debug:`dbg`,info:`inf`,warning:`wrn`,error:`err`,fatal:`ftl`},FULL:{trace:`TRACE`,debug:`DEBUG`,info:`INFO`,warning:`WARNING`,error:`ERROR`,fatal:`FATAL`},full:{trace:`trace`,debug:`debug`,info:`info`,warning:`warning`,error:`error`,fatal:`fatal`},L:{trace:`T`,debug:`D`,info:`I`,warning:`W`,error:`E`,fatal:`F`},l:{trace:`t`,debug:`d`,info:`i`,warning:`w`,error:`e`,fatal:`f`}};function getLineEndingValue(e){return e===`crlf`?`\r
3
+ `:`
4
+ `}function jsonReplacer(e,t){if(!(t instanceof Error))return t;let n={name:t.name,message:t.message};typeof t.stack==`string`&&(n.stack=t.stack);let r=t.cause;r!==void 0&&(n.cause=r),typeof AggregateError<`u`&&t instanceof AggregateError&&(n.errors=t.errors);for(let e of Object.keys(t))e in n||(n[e]=t[e]);return n}function getTextFormatter(e={}){let t=(()=>{let t=e.timestamp;return t==null?p[`date-time-timezone`]:t===`disabled`?p.none:typeof t==`string`&&t in p?p[t]:t})(),n=e.category??`·`,r=e.value?t=>e.value(t,f):f,i=(()=>{let t=e.level;return t==null||t===`ABBR`?e=>m.ABBR[e]:t===`abbr`?e=>m.abbr[e]:t===`FULL`?e=>m.FULL[e]:t===`full`?e=>m.full[e]:t===`L`?e=>m.L[e]:t===`l`?e=>m.l[e]:t})(),a=getLineEndingValue(e.lineEnding),o=e.format??(({timestamp:e,level:t,category:n,message:r})=>`${e?`${e} `:``}[${t}] ${n}: ${r}`);return e=>{let s=e.message,c=s.length,l;if(c===1)l=s[0];else if(c<=6){l=``;for(let e=0;e<c;e++)l+=e%2==0?s[e]:r(s[e])}else{let e=Array(c);for(let t=0;t<c;t++)e[t]=t%2==0?s[t]:r(s[t]);l=e.join(``)}return`${o({timestamp:t(e.timestamp),level:i(e.level),category:typeof n==`function`?n(e.category):e.category.join(n),message:l,record:e})}${a}`}}getTextFormatter();const h=`\x1B[0m`,g={black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},_={bold:`\x1B[1m`,dim:`\x1B[2m`,italic:`\x1B[3m`,underline:`\x1B[4m`,strikethrough:`\x1B[9m`},v={trace:null,debug:`blue`,info:`green`,warning:`yellow`,error:`red`,fatal:`magenta`};function getAnsiColorFormatter(e={}){let t=e.format,n=e.timestampStyle===void 0?`dim`:e.timestampStyle,r=e.timestampColor??null,i=`${n==null?``:_[n]}${r==null?``:g[r]}`,a=n==null&&r==null?``:h,o=e.levelStyle===void 0?`bold`:e.levelStyle,s=e.levelColors??v,c=e.categoryStyle===void 0?`dim`:e.categoryStyle,l=e.categoryColor??null,u=`${c==null?``:_[c]}${l==null?``:g[l]}`,d=c==null&&l==null?``:h;return getTextFormatter({timestamp:`date-time-tz`,value(e,t){return t(e,{colors:!0})},...e,format({timestamp:e,level:n,category:r,message:c,record:l}){let f=s[l.level];return e=e==null?null:`${i}${e}${a}`,n=`${o==null?``:_[o]}${f==null?``:g[f]}${n}${o==null&&f==null?``:h}`,t==null?`${e==null?``:`${e} `}${n} ${u}${r}:${d} ${c}`:t({timestamp:e,level:n,category:`${u}${r}${d}`,message:c,record:l})}})}getAnsiColorFormatter();function getJsonLinesFormatter(e={}){let t=getLineEndingValue(e.lineEnding);if(!e.categorySeparator&&!e.message&&!e.properties)return e=>{if(e.message.length===3)return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:e.message[0]+JSON.stringify(e.message[1])+e.message[2],logger:e.category.join(`.`),properties:e.properties},jsonReplacer)+t;if(e.message.length===1)return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:e.message[0],logger:e.category.join(`.`),properties:e.properties},jsonReplacer)+t;let n=e.message[0];for(let t=1;t<e.message.length;t++)n+=t&1?JSON.stringify(e.message[t]):e.message[t];return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:n,logger:e.category.join(`.`),properties:e.properties},jsonReplacer)+t};let n=e.message===`template`,r=e.properties??`nest:properties`,joinCategory;if(typeof e.categorySeparator==`function`)joinCategory=e.categorySeparator;else{let t=e.categorySeparator??`.`;joinCategory=e=>e.join(t)}let getProperties;if(r===`flatten`)getProperties=e=>e;else if(r.startsWith(`prepend:`)){let e=r.substring(8);if(e===``)throw TypeError(`Invalid properties option: ${JSON.stringify(r)}. It must be of the form "prepend:<prefix>" where <prefix> is a non-empty string.`);getProperties=t=>{let n={};for(let r in t)n[`${e}${r}`]=t[r];return n}}else if(r.startsWith(`nest:`)){let e=r.substring(5);getProperties=t=>({[e]:t})}else throw TypeError(`Invalid properties option: ${JSON.stringify(r)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);let i;return i=n?e=>{if(typeof e.rawMessage==`string`)return e.rawMessage;let t=``;for(let n=0;n<e.rawMessage.length;n++)t+=n%2<1?e.rawMessage[n]:`{}`;return t}:e=>{let t=e.message.length;if(t===1)return e.message[0];let n=``;for(let r=0;r<t;r++)n+=r%2<1?e.message[r]:JSON.stringify(e.message[r]);return n},e=>JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:i(e),logger:joinCategory(e.category),...getProperties(e.properties)},jsonReplacer)+t}getJsonLinesFormatter();const y={trace:`background-color: gray; color: white;`,debug:`background-color: gray; color: white;`,info:`background-color: white; color: black;`,warning:`background-color: orange; color: black;`,error:`background-color: red; color: white;`,fatal:`background-color: maroon; color: white;`};function defaultConsoleFormatter(e){let t=``,n=[];for(let r=0;r<e.message.length;r++)r%2==0?t+=e.message[r]:(t+=`%o`,n.push(e.message[r]));let r=new Date(e.timestamp);return[`%c${`${r.getUTCHours().toString().padStart(2,`0`)}:${r.getUTCMinutes().toString().padStart(2,`0`)}:${r.getUTCSeconds().toString().padStart(2,`0`)}.${r.getUTCMilliseconds().toString().padStart(3,`0`)}`} %c${d[e.level]}%c %c${e.category.join(`·`)} %c${t}`,`color: gray;`,y[e.level],`background-color: default;`,`color: gray;`,`color: default;`,...n]}function getConsoleSink(e={}){let t=e.formatter??defaultConsoleFormatter,n={trace:`debug`,debug:`debug`,info:`info`,warning:`warn`,error:`error`,fatal:`error`,...e.levelMap??{}},r=e.console??globalThis.console,baseSink=e=>{let i=t(e),a=n[e.level];if(a===void 0)throw TypeError(`Invalid log level: ${e.level}.`);if(typeof i==`string`){let e=i.replace(/\r?\n$/,``);r[a](e)}else r[a](...i)};if(!e.nonBlocking)return baseSink;let i=e.nonBlocking===!0?{}:e.nonBlocking,a=i.bufferSize??100,o=i.flushInterval??100,s=[],c=null,l=!1,u=!1,d=a*2;function flush(){if(s.length===0)return;let e=s.splice(0);for(let t of e)try{baseSink(t)}catch{}}function scheduleFlush(){u||(u=!0,setTimeout(()=>{u=!1,flush()},0))}function startFlushTimer(){c!==null||l||(c=setInterval(()=>{flush()},o))}let nonBlockingSink=e=>{l||(s.length>=d&&s.shift(),s.push(e),s.length>=a?scheduleFlush():c===null&&startFlushTimer())};return nonBlockingSink[Symbol.dispose]=()=>{l=!0,c!==null&&(clearInterval(c),c=null),flush()},nonBlockingSink}let b=null;const x=new Set,S=new Set,C=new Set;function isLoggerConfigMeta(e){return e.category.length===0||e.category.length===1&&e.category[0]===`logtape`||e.category.length===2&&e.category[0]===`logtape`&&e.category[1]===`meta`}function registerDisposeHook(e){let t=e?dispose:disposeSync;if(typeof globalThis.EdgeRuntime!=`string`&&`process`in globalThis&&!(`Deno`in globalThis)){let e=globalThis.process,n=e?.on;if(typeof n==`function`){n.call(e,`exit`,t);return}}let n=globalThis.addEventListener;typeof n==`function`&&(`Deno`in globalThis?n.call(globalThis,`unload`,t):n.call(globalThis,`pagehide`,t))}function configureSync(e){if(b!=null&&!e.reset)throw new ConfigError(`Already configured; if you want to reset, turn on the reset flag.`);if(C.size>0)throw new ConfigError(`Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().`);resetSync();try{configureInternal(e,!1)}catch(e){throw e instanceof ConfigError&&resetSync(),e}}function configureInternal(e,t){b=e;let n=!1,r=new Set;for(let t of e.loggers){isLoggerConfigMeta(t)&&(n=!0);let i=Array.isArray(t.category)?JSON.stringify(t.category):JSON.stringify([t.category]);if(r.has(i))throw new ConfigError(`Duplicate logger configuration for category: ${i}. Each category can only be configured once.`);r.add(i);let a=o.getLogger(t.category);for(let n of t.sinks??[]){let t=e.sinks[n];if(!t)throw new ConfigError(`Sink not found: ${n}.`);a.sinks.push(t)}a.parentSinks=t.parentSinks??`inherit`,t.lowestLevel!==void 0&&(a.lowestLevel=t.lowestLevel);for(let n of t.filters??[]){let t=e.filters?.[n];if(t===void 0)throw new ConfigError(`Filter not found: ${n}.`);a.filters.push(toFilter(t))}x.add(a)}o.getLogger().contextLocalStorage=e.contextLocalStorage;for(let n of Object.values(e.sinks)){if(Symbol.asyncDispose in n)if(t)C.add(n);else throw new ConfigError(`Async disposables cannot be used with configureSync().`);Symbol.dispose in n&&S.add(n)}for(let n of Object.values(e.filters??{}))if(!(n==null||typeof n==`string`)){if(Symbol.asyncDispose in n)if(t)C.add(n);else throw new ConfigError(`Async disposables cannot be used with configureSync().`);Symbol.dispose in n&&S.add(n)}registerDisposeHook(t);let i=o.getLogger([`logtape`,`meta`]);n||i.sinks.push(getConsoleSink()),i.info(`LogTape loggers are configured. Note that LogTape itself uses the meta logger, which has category {metaLoggerCategory}. The meta logger is used to log internal diagnostics such as sink exceptions. It's recommended to configure the meta logger with a separate sink so that you can easily notice if logging itself fails or is misconfigured. To turn off this message, configure the meta logger with higher log levels than {dismissLevel}. See also <https://logtape.org/manual/categories#meta-logger>.`,{metaLoggerCategory:[`logtape`,`meta`],dismissLevel:`info`})}function resetSync(){disposeSync(),resetInternal()}function resetInternal(){let e=o.getLogger([]);e.resetDescendants(),delete e.contextLocalStorage,x.clear(),b=null}async function dispose(){disposeSync();let e=[];for(let t of C)e.push(t[Symbol.asyncDispose]()),C.delete(t);await Promise.all(e)}function disposeSync(){for(let e of S)e[Symbol.dispose]();S.clear()}var ConfigError=class extends Error{constructor(e){super(e),this.name=`ConfigureError`}};export{getLogger as a,getTextFormatter as i,getConsoleSink as n,getAnsiColorFormatter as r,configureSync as t};
@@ -0,0 +1 @@
1
+ import"../../rolldown-runtime.mjs";function createMap(){return new e}var e=class IndexedMap{index={};array=[];size(){return this.array.length}empty(){return this.array.length===0}itemAt(e){return this.array[e]}contains(e){return this.index[e.id()]!==void 0}find(e){let t=this.index[e.id()];return t===void 0?void 0:this.array[t]}setDefault(e,n){let r=this.index[e.id()];if(r===void 0){let r=new t(e,n());return this.index[e.id()]=this.array.length,this.array.push(r),r}else return this.array[r]}insert(e,n){let r=new t(e,n),i=this.index[e.id()];return i===void 0?(this.index[e.id()]=this.array.length,this.array.push(r)):this.array[i]=r,r}erase(e){let t=this.index[e.id()];if(t===void 0)return;this.index[e.id()]=void 0;let n=this.array[t],r=this.array.pop();return n!==r&&(this.array[t]=r,this.index[r.first.id()]=t),n}copy(){let e=new IndexedMap;for(let t=0;t<this.array.length;t++){let n=this.array[t].copy();e.array[t]=n,e.index[n.first.id()]=t}return e}},t=class Pair{first;second;constructor(e,t){this.first=e,this.second=t}copy(){return new Pair(this.first,this.second)}},Variable=class{constructor(e=``){this._name=e}id(){return this._id}name(){return this._name}setName(e){this._name=e}context(){return this._context}setContext(e){this._context=e}value(){return this._value}setValue(e){this._value=e}plus(e){return new r(this,e)}minus(e){return new r(this,typeof e==`number`?-e:[-1,e])}multiply(e){return new r([e,this])}divide(e){return new r([1/e,this])}toJSON(){return{name:this._name,value:this._value}}toString(){return this._context+`[`+this._name+`:`+this._value+`]`}_name;_value=0;_context=null;_id=n++};let n=0;var r=class Expression{constructor(){let e=parseArgs(arguments);this._terms=e.terms,this._constant=e.constant}terms(){return this._terms}constant(){return this._constant}value(){let e=this._constant;for(let t=0,n=this._terms.size();t<n;t++){let n=this._terms.itemAt(t);e+=n.first.value()*n.second}return e}plus(e){return new Expression(this,e)}minus(e){return new Expression(this,typeof e==`number`?-e:[-1,e])}multiply(e){return new Expression([e,this])}divide(e){return new Expression([1/e,this])}isConstant(){return this._terms.size()==0}toString(){let e=this._terms.array.map(function(e){return e.second+`*`+e.first.toString()}).join(` + `);return!this.isConstant()&&this._constant!==0&&(e+=` + `),e+=this._constant,e}_terms;_constant};function parseArgs(e){let t=0,factory=()=>0,n=createMap();for(let i=0,a=e.length;i<a;++i){let a=e[i];if(typeof a==`number`)t+=a;else if(a instanceof Variable)n.setDefault(a,factory).second+=1;else if(a instanceof r){t+=a.constant();let e=a.terms();for(let t=0,r=e.size();t<r;t++){let r=e.itemAt(t);n.setDefault(r.first,factory).second+=r.second}}else if(a instanceof Array){if(a.length!==2)throw Error(`array must have length 2`);let e=a[0],i=a[1];if(typeof e!=`number`)throw Error(`array item 0 must be a number`);if(i instanceof Variable)n.setDefault(i,factory).second+=e;else if(i instanceof r){t+=i.constant()*e;let r=i.terms();for(let t=0,i=r.size();t<i;t++){let i=r.itemAt(t);n.setDefault(i.first,factory).second+=i.second*e}}else throw Error(`array item 1 must be a variable or expression`)}else throw Error(`invalid Expression argument: `+a)}return{terms:n,constant:t}}var i=class Strength{static create(e,t,n,r=1){let i=0;return i+=Math.max(0,Math.min(1e3,e*r))*1e6,i+=Math.max(0,Math.min(1e3,t*r))*1e3,i+=Math.max(0,Math.min(1e3,n*r)),i}static required=Strength.create(1e3,1e3,1e3);static strong=Strength.create(1,0,0);static medium=Strength.create(0,1,0);static weak=Strength.create(0,0,1);static clip(e){return Math.max(0,Math.min(Strength.required,e))}},a;(function(e){e[e.Le=0]=`Le`,e[e.Ge=1]=`Ge`,e[e.Eq=2]=`Eq`})(a||={});var Constraint=class{constructor(e,t,n,a=i.required){this._operator=t,this._strength=i.clip(a),n===void 0&&e instanceof r?this._expression=e:this._expression=e.minus(n)}id(){return this._id}expression(){return this._expression}op(){return this._operator}strength(){return this._strength}toString(){return this._expression.toString()+` `+[`<=`,`>=`,`=`][this._operator]+` 0 (`+this._strength.toString()+`)`}_expression;_operator;_strength;_id=o++};let o=0;var Solver=class{maxIterations=1e3;constructor(){}createConstraint(e,t,n,r=i.required){let a=new Constraint(e,t,n,r);return this.addConstraint(a),a}addConstraint(e){if(this._cnMap.find(e)!==void 0)throw Error(`duplicate constraint`);let t=this._createRow(e),n=t.row,r=t.tag,i=this._chooseSubject(n,r);if(i.type()===s.Invalid&&n.allDummies())if(nearZero(n.constant()))i=r.marker;else throw Error(`unsatisfiable constraint`);if(i.type()===s.Invalid){if(!this._addWithArtificialVariable(n))throw Error(`unsatisfiable constraint`)}else n.solveFor(i),this._substitute(i,n),this._rowMap.insert(i,n);this._cnMap.insert(e,r),this._optimize(this._objective)}removeConstraint(e){let t=this._cnMap.erase(e);if(t===void 0)throw Error(`unknown constraint`);this._removeConstraintEffects(e,t.second);let n=t.second.marker,r=this._rowMap.erase(n);if(r===void 0){let e=this._getMarkerLeavingSymbol(n);if(e.type()===s.Invalid)throw Error(`failed to find leaving row`);r=this._rowMap.erase(e),r.second.solveForEx(e,n),this._substitute(n,r.second)}this._optimize(this._objective)}hasConstraint(e){return this._cnMap.contains(e)}getConstraints(){return this._cnMap.array.map(({first:e})=>e)}addEditVariable(e,t){if(this._editMap.find(e)!==void 0)throw Error(`duplicate edit variable`);if(t=i.clip(t),t===i.required)throw Error(`bad required strength`);let n=new Constraint(new r(e),a.Eq,void 0,t);this.addConstraint(n);let o={tag:this._cnMap.find(n).second,constraint:n,constant:0};this._editMap.insert(e,o)}removeEditVariable(e){let t=this._editMap.erase(e);if(t===void 0)throw Error(`unknown edit variable`);this.removeConstraint(t.second.constraint)}hasEditVariable(e){return this._editMap.contains(e)}suggestValue(e,t){let n=this._editMap.find(e);if(n===void 0)throw Error(`unknown edit variable`);let r=this._rowMap,i=n.second,a=t-i.constant;i.constant=t;let o=i.tag.marker,c=r.find(o);if(c!==void 0){c.second.add(-a)<0&&this._infeasibleRows.push(o),this._dualOptimize();return}let l=i.tag.other;if(c=r.find(l),c!==void 0){c.second.add(a)<0&&this._infeasibleRows.push(l),this._dualOptimize();return}for(let e=0,t=r.size();e<t;++e){let t=r.itemAt(e),n=t.second,i=n.coefficientFor(o);i!==0&&n.add(a*i)<0&&t.first.type()!==s.External&&this._infeasibleRows.push(t.first)}this._dualOptimize()}updateVariables(){let e=this._varMap,t=this._rowMap;for(let n=0,r=e.size();n<r;++n){let r=e.itemAt(n),i=t.find(r.second);i===void 0?r.first.setValue(0):r.first.setValue(i.second.constant())}}_getVarSymbol(e){let factory=()=>this._makeSymbol(s.External);return this._varMap.setDefault(e,factory).second}_createRow(e){let t=e.expression(),n=new l(t.constant()),r=t.terms();for(let e=0,t=r.size();e<t;++e){let t=r.itemAt(e);if(!nearZero(t.second)){let e=this._getVarSymbol(t.first),r=this._rowMap.find(e);r===void 0?n.insertSymbol(e,t.second):n.insertRow(r.second,t.second)}}let o=this._objective,u=e.strength(),d={marker:c,other:c};switch(e.op()){case a.Le:case a.Ge:{let t=e.op()===a.Le?1:-1,r=this._makeSymbol(s.Slack);if(d.marker=r,n.insertSymbol(r,t),u<i.required){let e=this._makeSymbol(s.Error);d.other=e,n.insertSymbol(e,-t),o.insertSymbol(e,u)}break}case a.Eq:if(u<i.required){let e=this._makeSymbol(s.Error),t=this._makeSymbol(s.Error);d.marker=e,d.other=t,n.insertSymbol(e,-1),n.insertSymbol(t,1),o.insertSymbol(e,u),o.insertSymbol(t,u)}else{let e=this._makeSymbol(s.Dummy);d.marker=e,n.insertSymbol(e)}break}return n.constant()<0&&n.reverseSign(),{row:n,tag:d}}_chooseSubject(e,t){let n=e.cells();for(let e=0,t=n.size();e<t;++e){let t=n.itemAt(e);if(t.first.type()===s.External)return t.first}let r=t.marker.type();return(r===s.Slack||r===s.Error)&&e.coefficientFor(t.marker)<0?t.marker:(r=t.other.type(),(r===s.Slack||r===s.Error)&&e.coefficientFor(t.other)<0?t.other:c)}_addWithArtificialVariable(e){let t=this._makeSymbol(s.Slack);this._rowMap.insert(t,e.copy()),this._artificial=e.copy(),this._optimize(this._artificial);let n=nearZero(this._artificial.constant());this._artificial=null;let r=this._rowMap.erase(t);if(r!==void 0){let e=r.second;if(e.isConstant())return n;let i=this._anyPivotableSymbol(e);if(i.type()===s.Invalid)return!1;e.solveForEx(t,i),this._substitute(i,e),this._rowMap.insert(i,e)}let i=this._rowMap;for(let e=0,n=i.size();e<n;++e)i.itemAt(e).second.removeSymbol(t);return this._objective.removeSymbol(t),n}_substitute(e,t){let n=this._rowMap;for(let r=0,i=n.size();r<i;++r){let i=n.itemAt(r);i.second.substitute(e,t),i.second.constant()<0&&i.first.type()!==s.External&&this._infeasibleRows.push(i.first)}this._objective.substitute(e,t),this._artificial&&this._artificial.substitute(e,t)}_optimize(e){let t=0;for(;t<this.maxIterations;){let n=this._getEnteringSymbol(e);if(n.type()===s.Invalid)return;let r=this._getLeavingSymbol(n);if(r.type()===s.Invalid)throw Error(`the objective is unbounded`);let i=this._rowMap.erase(r).second;i.solveForEx(r,n),this._substitute(n,i),this._rowMap.insert(n,i),t++}throw Error(`solver iterations exceeded`)}_dualOptimize(){let e=this._rowMap,t=this._infeasibleRows;for(;t.length!==0;){let n=t.pop(),r=e.find(n);if(r!==void 0&&r.second.constant()<0){let t=this._getDualEnteringSymbol(r.second);if(t.type()===s.Invalid)throw Error(`dual optimize failed`);let i=r.second;e.erase(n),i.solveForEx(n,t),this._substitute(t,i),e.insert(t,i)}}}_getEnteringSymbol(e){let t=e.cells();for(let e=0,n=t.size();e<n;++e){let n=t.itemAt(e),r=n.first;if(n.second<0&&r.type()!==s.Dummy)return r}return c}_getDualEnteringSymbol(e){let t=Number.MAX_VALUE,n=c,r=e.cells();for(let e=0,i=r.size();e<i;++e){let i=r.itemAt(e),a=i.first,o=i.second;if(o>0&&a.type()!==s.Dummy){let e=this._objective.coefficientFor(a)/o;e<t&&(t=e,n=a)}}return n}_getLeavingSymbol(e){let t=Number.MAX_VALUE,n=c,r=this._rowMap;for(let i=0,a=r.size();i<a;++i){let a=r.itemAt(i),o=a.first;if(o.type()!==s.External){let r=a.second,i=r.coefficientFor(e);if(i<0){let e=-r.constant()/i;e<t&&(t=e,n=o)}}}return n}_getMarkerLeavingSymbol(e){let t=Number.MAX_VALUE,n=t,r=t,i=c,a=i,o=i,l=i,u=this._rowMap;for(let t=0,i=u.size();t<i;++t){let i=u.itemAt(t),c=i.second,d=c.coefficientFor(e);if(d===0)continue;let f=i.first;if(f.type()===s.External)l=f;else if(d<0){let e=-c.constant()/d;e<n&&(n=e,a=f)}else{let e=c.constant()/d;e<r&&(r=e,o=f)}}return a===i?o===i?l:o:a}_removeConstraintEffects(e,t){t.marker.type()===s.Error&&this._removeMarkerEffects(t.marker,e.strength()),t.other.type()===s.Error&&this._removeMarkerEffects(t.other,e.strength())}_removeMarkerEffects(e,t){let n=this._rowMap.find(e);n===void 0?this._objective.insertSymbol(e,-t):this._objective.insertRow(n.second,-t)}_anyPivotableSymbol(e){let t=e.cells();for(let e=0,n=t.size();e<n;++e){let n=t.itemAt(e),r=n.first.type();if(r===s.Slack||r===s.Error)return n.first}return c}_makeSymbol(e){return new Symbol(e,this._idTick++)}_cnMap=createCnMap();_rowMap=createRowMap();_varMap=createVarMap();_editMap=createEditMap();_infeasibleRows=[];_objective=new l;_artificial=null;_idTick=0};function nearZero(e){let t=1e-8;return e<0?-e<t:e<t}function createCnMap(){return createMap()}function createRowMap(){return createMap()}function createVarMap(){return createMap()}function createEditMap(){return createMap()}var s;(function(e){e[e.Invalid=0]=`Invalid`,e[e.External=1]=`External`,e[e.Slack=2]=`Slack`,e[e.Error=3]=`Error`,e[e.Dummy=4]=`Dummy`})(s||={});var Symbol=class{constructor(e,t){this._id=t,this._type=e}id(){return this._id}type(){return this._type}_id;_type};let c=new Symbol(s.Invalid,-1);var l=class Row{constructor(e=0){this._constant=e}cells(){return this._cellMap}constant(){return this._constant}isConstant(){return this._cellMap.empty()}allDummies(){let e=this._cellMap;for(let t=0,n=e.size();t<n;++t)if(e.itemAt(t).first.type()!==s.Dummy)return!1;return!0}copy(){let e=new Row(this._constant);return e._cellMap=this._cellMap.copy(),e}add(e){return this._constant+=e}insertSymbol(e,t=1){let n=this._cellMap.setDefault(e,()=>0);nearZero(n.second+=t)&&this._cellMap.erase(e)}insertRow(e,t=1){this._constant+=e._constant*t;let n=e._cellMap;for(let e=0,r=n.size();e<r;++e){let r=n.itemAt(e);this.insertSymbol(r.first,r.second*t)}}removeSymbol(e){this._cellMap.erase(e)}reverseSign(){this._constant=-this._constant;let e=this._cellMap;for(let t=0,n=e.size();t<n;++t){let n=e.itemAt(t);n.second=-n.second}}solveFor(e){let t=this._cellMap,n=-1/t.erase(e).second;this._constant*=n;for(let e=0,r=t.size();e<r;++e)t.itemAt(e).second*=n}solveForEx(e,t){this.insertSymbol(e,-1),this.solveFor(t)}coefficientFor(e){let t=this._cellMap.find(e);return t===void 0?0:t.second}substitute(e,t){let n=this._cellMap.erase(e);n!==void 0&&this.insertRow(t,n.second)}_cellMap=createMap();_constant};export{Variable as a,i,Constraint as n,a as r,Solver as t};