likec4 1.59.4 → 1.61.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 (186) hide show
  1. package/README.md +2 -0
  2. package/__app__/codegen/react.mjs +4 -10
  3. package/__app__/codegen/webcomponent.mjs +6 -131
  4. package/__app__/index.html +15 -15
  5. package/__app__/src/aichat/index.mjs +11 -7
  6. package/__app__/src/chunks/AIChat.mjs +1355 -739
  7. package/__app__/src/chunks/ErrorComponent.mjs +444 -0
  8. package/__app__/src/chunks/Header.mjs +269 -0
  9. package/__app__/src/chunks/ViewReact.mjs +438 -0
  10. package/__app__/src/chunks/find.mjs +38 -0
  11. package/__app__/src/chunks/hooks.mjs +158 -472
  12. package/__app__/src/chunks/libs/@tabler/icons-react.mjs +340 -0
  13. package/__app__/src/chunks/libs/@tanstack-ai.mjs +11841 -1417
  14. package/__app__/src/chunks/libs/@tanstack.mjs +5110 -2404
  15. package/__app__/src/chunks/libs/fast-equals.mjs +507 -214
  16. package/__app__/src/chunks/libs/html-to-image.mjs +613 -0
  17. package/__app__/src/chunks/libs/nanostores.mjs +170 -0
  18. package/__app__/src/chunks/libs/react-resizable-panels.mjs +2792 -0
  19. package/__app__/src/chunks/react.mjs +22 -0
  20. package/__app__/src/chunks/rolldown-runtime.mjs +16 -29
  21. package/__app__/src/chunks/router.mjs +106 -0
  22. package/__app__/src/chunks/scope.mjs +106 -0
  23. package/__app__/src/chunks/searchParams.mjs +29 -0
  24. package/__app__/src/chunks/single-index.mjs +465 -0
  25. package/__app__/src/chunks/styled-system.mjs +1826 -2528
  26. package/__app__/src/chunks/useAsync.mjs +69 -0
  27. package/__app__/src/chunks/useSyncedRef.mjs +16 -0
  28. package/__app__/src/components/ColorSchemeToggle.mjs +124 -0
  29. package/__app__/src/components/CopyToClipboard.mjs +53 -0
  30. package/__app__/src/components/ErrorComponent.mjs +1 -0
  31. package/__app__/src/components/NavigationPanel.mjs +63 -0
  32. package/__app__/src/components/NotFound.mjs +155 -0
  33. package/__app__/src/components/ViewOutlet.mjs +9 -0
  34. package/__app__/src/components/model-diff/CompareModelProvider.mjs +44 -0
  35. package/__app__/src/components/model-diff/ModelDiffPanel.mjs +179 -0
  36. package/__app__/src/components/model-diff/compare-model.mjs +76 -0
  37. package/__app__/src/components/model-diff/state.mjs +45 -0
  38. package/__app__/src/components/search/OverviewSearch.mjs +92 -0
  39. package/__app__/src/components/search/OverviewSearchAdapter.mjs +94 -0
  40. package/__app__/src/components/sidebar/DiagramTree.css.mjs +48 -0
  41. package/__app__/src/components/sidebar/DiagramsTree.mjs +304 -0
  42. package/__app__/src/components/sidebar/Drawer.mjs +178 -0
  43. package/__app__/src/components/sidebar/SidebarBurger.mjs +28 -0
  44. package/__app__/src/components/sidebar/data.mjs +94 -0
  45. package/__app__/src/components/sidebar/state.mjs +16 -0
  46. package/__app__/src/components/view-page/Header.mjs +1 -0
  47. package/__app__/src/components/view-page/SelectProject.mjs +258 -0
  48. package/__app__/src/components/view-page/ShareModal.mjs +111 -0
  49. package/__app__/src/components/view-page/share-modal/AlertLocalhost.mjs +31 -0
  50. package/__app__/src/components/view-page/share-modal/CopyButtonChild.mjs +36 -0
  51. package/__app__/src/components/view-page/share-modal/EmbedPanel.mjs +100 -0
  52. package/__app__/src/components/view-page/share-modal/WebcomponentsPanel.mjs +264 -0
  53. package/__app__/src/components/view-page/state.mjs +17 -0
  54. package/__app__/src/context/LikeC4CustomizationContext.mjs +26 -0
  55. package/__app__/src/context/LikeC4IconRendererContext.mjs +29 -0
  56. package/__app__/src/context/LikeC4ModelContext.mjs +34 -0
  57. package/__app__/src/context/LikeC4ProjectsContext.mjs +40 -0
  58. package/__app__/src/context/ModelDiffsContext.mjs +33 -0
  59. package/__app__/src/context/safeCtx.mjs +14 -0
  60. package/__app__/src/fonts.css +112 -1
  61. package/__app__/src/hooks.mjs +1 -0
  62. package/__app__/src/main.mjs +6 -29151
  63. package/__app__/src/pages/EmbedPage.mjs +93 -0
  64. package/__app__/src/pages/ExportPage.mjs +691 -0
  65. package/__app__/src/pages/ProjectsOverview.mjs +23 -0
  66. package/__app__/src/pages/ViewAsD2.mjs +105 -0
  67. package/__app__/src/pages/ViewAsDot.mjs +65 -0
  68. package/__app__/src/pages/ViewAsMmd.mjs +109 -0
  69. package/__app__/src/pages/ViewAsPuml.mjs +105 -0
  70. package/__app__/src/pages/ViewEditor.mjs +220 -0
  71. package/__app__/src/pages/ViewReact.mjs +1 -0
  72. package/__app__/src/pages/export-layout.mjs +95 -0
  73. package/__app__/src/pages/export-page-params.mjs +9 -0
  74. package/__app__/src/pages/styles.css.mjs +23 -0
  75. package/__app__/src/routeTree.gen.mjs +105 -0
  76. package/__app__/src/router.mjs +1 -0
  77. package/__app__/src/routes/__root.mjs +65 -0
  78. package/__app__/src/routes/index.css.mjs +29 -0
  79. package/__app__/src/routes/index.mjs +32 -0
  80. package/__app__/src/routes/project._projectId/-components.mjs +100 -0
  81. package/__app__/src/routes/project._projectId/embed._viewId.mjs +5 -0
  82. package/__app__/src/routes/project._projectId/export._viewId.mjs +24 -0
  83. package/__app__/src/routes/project._projectId/index.mjs +14 -0
  84. package/__app__/src/routes/project._projectId/route.mjs +93 -0
  85. package/__app__/src/routes/project._projectId/view._viewId.d2.mjs +34 -0
  86. package/__app__/src/routes/project._projectId/view._viewId.dot.mjs +41 -0
  87. package/__app__/src/routes/project._projectId/view._viewId.index.mjs +7 -0
  88. package/__app__/src/routes/project._projectId/view._viewId.mjs +23 -0
  89. package/__app__/src/routes/project._projectId/view._viewId.mmd.mjs +39 -0
  90. package/__app__/src/routes/project._projectId/view._viewId.puml.mjs +34 -0
  91. package/__app__/src/routes/projects.mjs +36 -0
  92. package/__app__/src/routes/single-index.mjs +1 -0
  93. package/__app__/src/routes/webcomponent._.mjs +94 -0
  94. package/__app__/src/style.css +18497 -1
  95. package/config/schema.json +146 -97
  96. package/dist/app/render-view-client.css +1 -1
  97. package/dist/app/render-view-client.js +394 -238
  98. package/dist/chunks/enableServer.mjs +1 -1
  99. package/dist/chunks/filenames.mjs +25 -17
  100. package/dist/chunks/generate-likec4.mjs +5 -0
  101. package/dist/chunks/index.d.mts +255 -194
  102. package/dist/chunks/index2.d.mts +8246 -3610
  103. package/dist/chunks/libs/@chenglou/pretext.mjs +9 -0
  104. package/dist/chunks/libs/@chevrotain/gast.mjs +27 -1
  105. package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +81 -9
  106. package/dist/chunks/libs/@logtape/logtape.mjs +5 -4
  107. package/dist/chunks/libs/@lume/kiwi.mjs +1 -1
  108. package/dist/chunks/libs/@ts-graphviz/common.d.mts +2 -4
  109. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
  110. package/dist/chunks/libs/birpc.mjs +1 -1
  111. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  112. package/dist/chunks/libs/chevrotain.mjs +88 -36
  113. package/dist/chunks/libs/clone.mjs +1 -0
  114. package/dist/chunks/libs/eventemitter3.mjs +1 -1
  115. package/dist/chunks/libs/fast-equals.mjs +1 -0
  116. package/dist/chunks/libs/fontkit.mjs +1 -0
  117. package/dist/chunks/libs/json5.mjs +4 -4
  118. package/dist/chunks/libs/langium.d.mts +6707 -6715
  119. package/dist/chunks/libs/langium.mjs +16 -24
  120. package/dist/chunks/libs/merge-error-cause.mjs +1 -1
  121. package/dist/chunks/libs/p-limit.mjs +1 -0
  122. package/dist/chunks/libs/p-queue.mjs +1 -1
  123. package/dist/chunks/libs/package-manager-detector.mjs +1 -1
  124. package/dist/chunks/libs/pako.mjs +1 -1
  125. package/dist/chunks/libs/pathe.mjs +1 -1
  126. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  127. package/dist/chunks/libs/remeda.mjs +1 -1
  128. package/dist/chunks/libs/ufo.mjs +1 -1
  129. package/dist/chunks/libs/unstorage.mjs +1 -1
  130. package/dist/chunks/libs/which.mjs +1 -1
  131. package/dist/chunks/node.mjs +111 -77
  132. package/dist/chunks/rolldown-runtime.mjs +1 -1
  133. package/dist/chunks/sequence-view.mjs +1 -1
  134. package/dist/chunks/vite-plugin.mjs +185 -166
  135. package/dist/cli/index.mjs +254 -1306
  136. package/dist/config/index.d.mts +66 -5
  137. package/dist/config/index.mjs +1 -1
  138. package/dist/generators/likec4.d.mts +6530 -0
  139. package/dist/generators/likec4.mjs +1 -0
  140. package/dist/index.d.mts +2 -4
  141. package/dist/model/index.d.mts +0 -7
  142. package/dist/vite-plugin/index.d.mts +83 -58
  143. package/dist/vite-plugin/index.mjs +1 -1
  144. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +8 -0
  145. package/dist/vite-plugin/internal/index.d.mts +92 -17
  146. package/dist/vite-plugin/internal/index.mjs +225 -126
  147. package/generators/likec4/package.json +4 -0
  148. package/package.json +134 -122
  149. package/react/index.d.mts +7496 -26659
  150. package/react/index.mjs +533 -63936
  151. package/react/rolldown-runtime-CfRud99p.js +1 -0
  152. package/skills/likec4-dsl/SKILL.md +474 -0
  153. package/skills/likec4-dsl/evals/evals-public.json +207 -0
  154. package/skills/likec4-dsl/evals/grading-spec.json +603 -0
  155. package/skills/likec4-dsl/references/bridge-leanix-drawio.md +42 -0
  156. package/skills/likec4-dsl/references/cli.md +168 -0
  157. package/skills/likec4-dsl/references/configuration.md +266 -0
  158. package/skills/likec4-dsl/references/deployment.md +160 -0
  159. package/skills/likec4-dsl/references/diffs.md +52 -0
  160. package/skills/likec4-dsl/references/dynamic-views.md +455 -0
  161. package/skills/likec4-dsl/references/examples.md +370 -0
  162. package/skills/likec4-dsl/references/identifier-validity.md +90 -0
  163. package/skills/likec4-dsl/references/include-predicates-wildcards.md +180 -0
  164. package/skills/likec4-dsl/references/model.md +182 -0
  165. package/skills/likec4-dsl/references/predicates.md +123 -0
  166. package/skills/likec4-dsl/references/relationships-bidirectional.md +176 -0
  167. package/skills/likec4-dsl/references/specification.md +79 -0
  168. package/skills/likec4-dsl/references/style-tokens-colors.md +150 -0
  169. package/skills/likec4-dsl/references/troubleshooting.md +101 -0
  170. package/skills/likec4-dsl/references/views.md +329 -0
  171. package/vite-plugin-modules.d.ts +126 -51
  172. package/__app__/src/chunks/LikeC4Styles.mjs +0 -2306
  173. package/__app__/src/chunks/ProjectsOverview.mjs +0 -537
  174. package/__app__/src/chunks/es.mjs +0 -439
  175. package/__app__/src/chunks/libs/@floating-ui.mjs +0 -2532
  176. package/__app__/src/chunks/libs/@mantine.mjs +0 -13868
  177. package/__app__/src/chunks/libs/@xstate/react.mjs +0 -2015
  178. package/__app__/src/chunks/libs/@xyflow/react.mjs +0 -5367
  179. package/__app__/src/chunks/libs/bezier-js.mjs +0 -1007
  180. package/__app__/src/chunks/libs/d3.mjs +0 -2817
  181. package/__app__/src/chunks/libs/framer.mjs +0 -5926
  182. package/__app__/src/chunks/libs/zod.mjs +0 -3176
  183. package/dist/chunks/libs/@chevrotain/types.d.mts +0 -108
  184. package/dist/chunks/libs/picomatch.mjs +0 -1
  185. package/dist/chunks/libs/zod.d.mts +0 -3840
  186. package/dist/chunks/libs/zod.mjs +0 -65
@@ -1,402 +1,806 @@
1
- import { i as e } from "./rolldown-runtime.mjs";
2
- import { c as t } from "./libs/@tanstack.mjs";
3
- import { C as n, F as r, N as i, O as a, _ as o, b as s, c, j as l, k as u, m as d, t as f, v as p, y as m } from "./hooks.mjs";
4
- import { At as h, C as g, F as _, H as v, Z as ee, _t as te, b as y, et as b, nn as ne, r as re, v as ie, vt as x } from "./libs/@mantine.mjs";
5
- import { C as S, L as C, T as w, y as T } from "./styled-system.mjs";
6
- import { i as ae, m as oe } from "./libs/framer.mjs";
7
- import { a as E, c as D, i as se, n as O, o as k, r as A, s as j, t as M } from "./libs/zod.mjs";
8
- import { a as N, i as ce, n as le, r as ue, t as de } from "./libs/@tanstack-ai.mjs";
9
- import { createContext as fe, use as pe, useEffect as me, useRef as P, useState as he } from "react";
10
- import { c as F } from "react/compiler-runtime";
11
- import { Fragment as I, jsx as L, jsxs as R } from "react/jsx-runtime";
12
- import { RichText as ge, nonNullable as _e, nonexhaustive as ve } from "@likec4/core";
13
- import { ElementShapes as ye } from "@likec4/core/styles";
14
- import { AIAdapter as be } from "likec4:rpc";
15
- //#region ../../node_modules/.pnpm/nanostores@1.5.3/node_modules/nanostores/computed/index.js
16
- var computedStore = (e, t, n) => {
17
- Array.isArray(e) || (e = [e]);
18
- let r, i, set = () => {
19
- if (i === s.epoch) return;
20
- i = s.epoch;
21
- let n = e.map((e) => e.get());
22
- if (!r?.every((t, r) => e[r].eq(t, n[r]))) {
23
- r = n;
24
- let e = t(...n);
25
- e && e.then && e.t ? e.then((e) => {
26
- r === n && a.set(e);
27
- }) : (a.set(e), i = s.epoch);
1
+ import { r as __name } from "./rolldown-runtime.mjs";
2
+ import { f as css, i as HStack, o as VStack, r as Txt } from "./styled-system.mjs";
3
+ import { t as useSyncedRef } from "./useSyncedRef.mjs";
4
+ import { v as createReactComponent } from "./libs/@tabler/icons-react.mjs";
5
+ import { a as toolDefinition, i as fetchServerSentEvents, n as useChat$1, r as clientTools, t as ChatMessage$1 } from "./libs/@tanstack-ai.mjs";
6
+ import { t as useStore } from "./react.mjs";
7
+ import { i as nanostoresGlobal, n as onMount, r as atom } from "./libs/nanostores.mjs";
8
+ import { c as useNavigate } from "./libs/@tanstack.mjs";
9
+ import { a as a$2, c as r$1, i as t, l as t$1, n as e, o as e$1, r as n, s as n$1, t as a$3 } from "./find.mjs";
10
+ import { t as useCurrentProject } from "./hooks.mjs";
11
+ import { createContext, use, useCallback, useEffect, useRef, useState } from "react";
12
+ import { c } from "react/compiler-runtime";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ import { ActionIcon, Badge, Button, CloseButton, FloatingWindow, Modal, Notification, ScrollAreaAutosize, Textarea, Title, Tooltip } from "@mantine/core";
15
+ import { Markdown, useDiagram } from "likec4/react";
16
+ import { useLocalStorage } from "@mantine/hooks";
17
+ import { z } from "zod";
18
+ import { AnimatePresence, m } from "motion/react";
19
+ import { RichText, nonNullable, nonexhaustive } from "@likec4/core";
20
+ import { AIAdapter } from "likec4:rpc";
21
+ import { ElementShapes } from "@likec4/core/styles";
22
+ // ../../node_modules/.pnpm/remeda@2.52.0/node_modules/remeda/dist/map.js
23
+ function r(...t$2) {
24
+ return t(i, t$2, a$1);
25
+ }
26
+ var i = (e, t) => e.map(t);
27
+ var a$1 = /* @__PURE__ */ __name((e$2) => n(e$2) ? e((t, n, r) => e$2(t, n, r)) : e$2, "a");
28
+ // ../../node_modules/.pnpm/remeda@2.52.0/node_modules/remeda/dist/pipe-D-eT-Ko7.js
29
+ var a = "Remeda: unexpected access to a callback's `data` argument during lazy evaluation.";
30
+ var o = /^(?:0|[1-9]\d*)$/u;
31
+ var s = new Proxy([{ error: a }], {
32
+ get: c$1,
33
+ getOwnPropertyDescriptor: c$1,
34
+ has: c$1,
35
+ ownKeys: l,
36
+ defineProperty: l,
37
+ deleteProperty: l,
38
+ preventExtensions: l,
39
+ set: l,
40
+ setPrototypeOf: l
41
+ });
42
+ function c$1(e, t) {
43
+ (t in Array.prototype || o.test(String(t))) && l();
44
+ }
45
+ __name(c$1, "c");
46
+ function l() {
47
+ throw Error(a);
48
+ }
49
+ function u(t, n, r) {
50
+ let i = n(...r);
51
+ let a = i.requiresData ? [] : void 0;
52
+ let o = a ?? s;
53
+ let c = a$2();
54
+ let l = [];
55
+ let u = 0;
56
+ if (Array.isArray(t)) for (let e of t) {
57
+ a?.push(e);
58
+ let t = d(i(e, u, o, c), l, c);
59
+ if (u += 1, t) break;
60
+ }
61
+ else for (let e of t) {
62
+ a?.push(e);
63
+ let t = d(i(e, u, o, c), l, c);
64
+ if (u += 1, t) break;
65
+ }
66
+ return n.single ? l[0] : l;
67
+ }
68
+ function d(e, a, o) {
69
+ if (typeof e == `symbol`) {
70
+ if (e === e$1) return !1;
71
+ if (e === r$1) {
72
+ for (let e of o.values) a.push(e);
73
+ return !1;
74
+ }
75
+ if (e === n$1) return a.push(o.value), !0;
76
+ if (e === t$1) return !0;
77
+ }
78
+ return a.push(e), !1;
79
+ }
80
+ function f(e, ...t) {
81
+ if (t.length === 0) return e;
82
+ if (t.length === 1) {
83
+ let n = t[0];
84
+ return `lazy` in n ? u(e, n.lazy, n.lazyArgs) : n(e);
85
+ }
86
+ let n = e;
87
+ let r = 0;
88
+ for (; r < t.length;) {
89
+ let e = t[r];
90
+ if (!(`lazy` in e)) {
91
+ n = e(n), r += 1;
92
+ continue;
93
+ }
94
+ let i = t[r + 1];
95
+ if (i === void 0 || !(`lazy` in i) || e.lazy.single) {
96
+ n = u(n, e.lazy, e.lazyArgs), r += 1;
97
+ continue;
98
+ }
99
+ let a = p(t, r);
100
+ n = m$1(n, a), r += a.length, t[r - 1].lazy.single && (n = n[0]);
101
+ }
102
+ return n;
103
+ }
104
+ function p(e, t) {
105
+ let n = [];
106
+ for (let r = t; r < e.length; r++) {
107
+ let t = e[r];
108
+ if (!(`lazy` in t)) break;
109
+ let i = t.lazy(...t.lazyArgs);
110
+ if (n.push(i.requiresData ? {
111
+ lazyEvaluator: i,
112
+ index: 0,
113
+ requiresData: !0,
114
+ items: []
115
+ } : {
116
+ lazyEvaluator: i,
117
+ index: 0,
118
+ requiresData: !1,
119
+ items: s
120
+ }), t.lazy.single) break;
121
+ }
122
+ return n;
123
+ }
124
+ function m$1(t, n) {
125
+ let r = [];
126
+ let i = a$2();
127
+ if (Array.isArray(t)) {
128
+ for (let e of t) if (h(n, r, e, i, 0)) break;
129
+ } else for (let e of t) if (h(n, r, e, i, 0)) break;
130
+ return r;
131
+ }
132
+ __name(m$1, "m");
133
+ function h(e, a, o, s, c) {
134
+ let l = o;
135
+ let u = !1;
136
+ for (let o = c; o < e.length; o++) {
137
+ let c = e[o];
138
+ c.requiresData && c.items.push(l);
139
+ let { lazyEvaluator: d } = c, f = d(l, c.index, c.items, s);
140
+ if (c.index += 1, typeof f == `symbol`) {
141
+ if (f === e$1) return u;
142
+ if (f === r$1) {
143
+ for (let t of s.values) if (h(e, a, t, s, o + 1)) return !0;
144
+ return u;
145
+ }
146
+ if (f === n$1) {
147
+ l = s.value, u = !0;
148
+ continue;
149
+ }
150
+ if (f === t$1) return !0;
28
151
  }
29
- }, a = /* @__PURE__ */ m(), o = a.get;
30
- a.get = () => (set(), o());
31
- let c, l = n ? () => {
32
- clearTimeout(c), c = setTimeout(set);
152
+ l = f;
153
+ }
154
+ return a.push(l), u;
155
+ }
156
+ /**
157
+ * @license @tabler/icons-react v3.49.0 - MIT
158
+ *
159
+ * This source code is licensed under the MIT license.
160
+ * See the LICENSE file in the root directory of this source tree.
161
+ */
162
+ var IconSparkles = createReactComponent("outline", "sparkles", "Sparkles", [["path", {
163
+ "d": "M16 18a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2m0 -12a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2m-7 12a6 6 0 0 1 6 -6a6 6 0 0 1 -6 -6a6 6 0 0 1 -6 6a6 6 0 0 1 6 6",
164
+ "key": "svg-0"
165
+ }]]);
166
+ /**
167
+ * @license @tabler/icons-react v3.49.0 - MIT
168
+ *
169
+ * This source code is licensed under the MIT license.
170
+ * See the LICENSE file in the root directory of this source tree.
171
+ */
172
+ var IconPlayerStopFilled = createReactComponent("filled", "player-stop-filled", "PlayerStopFilled", [["path", {
173
+ "d": "M17 4h-10a3 3 0 0 0 -3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3 -3v-10a3 3 0 0 0 -3 -3z",
174
+ "key": "svg-0"
175
+ }]]);
176
+ // ../../node_modules/.pnpm/@react-hookz+web@26.1.0_react-dom@19.3.1_react@19.3.1__react@19.3.1/node_modules/@react-hookz/web/dist/useTimeoutEffect/index.js
177
+ var cancelTimeout = (id) => {
178
+ if (id) clearTimeout(id);
179
+ };
180
+ /**
181
+ * Like `setTimeout` but in the form of a react hook.
182
+ *
183
+ * @param callback Callback to be called after the timeout. Changing this
184
+ * will not reset the timeout.
185
+ * @param ms Timeout delay in milliseconds. `undefined` disables the timeout.
186
+ * Keep in mind, that changing this parameter will re-set timeout, meaning
187
+ * that it will be set as new after the change.
188
+ */
189
+ function useTimeoutEffect(callback, ms) {
190
+ const cbRef = useSyncedRef(callback);
191
+ const msRef = useSyncedRef(ms);
192
+ const timeoutIdRef = useRef(null);
193
+ const cancel = useCallback(() => {
194
+ cancelTimeout(timeoutIdRef.current);
195
+ }, []);
196
+ const reset = useCallback(() => {
197
+ if (msRef.current === void 0) return;
198
+ cancel();
199
+ timeoutIdRef.current = setTimeout(() => {
200
+ cbRef.current();
201
+ }, msRef.current);
202
+ }, []);
203
+ useEffect(() => {
204
+ reset();
205
+ return cancel;
206
+ }, [ms]);
207
+ return [cancel, reset];
208
+ }
209
+ // ../../node_modules/.pnpm/nanostores@1.5.5/node_modules/nanostores/computed/index.js
210
+ var computedStore = (stores, cb, batched) => {
211
+ if (!Array.isArray(stores)) stores = [stores];
212
+ let previousArgs;
213
+ let currentEpoch;
214
+ let set = () => {
215
+ if (currentEpoch === nanostoresGlobal.epoch) return;
216
+ currentEpoch = nanostoresGlobal.epoch;
217
+ let args = stores.map(($store) => $store.get());
218
+ if (!previousArgs?.every((arg, i) => stores[i].eq(arg, args[i]))) {
219
+ previousArgs = args;
220
+ let value = cb(...args);
221
+ if (value && value.then && value.t) value.then((asyncValue) => {
222
+ if (previousArgs === args) $computed.set(asyncValue);
223
+ });
224
+ else {
225
+ $computed.set(value);
226
+ currentEpoch = nanostoresGlobal.epoch;
227
+ }
228
+ }
229
+ };
230
+ let $computed = /* @__PURE__ */ atom();
231
+ let get = $computed.get;
232
+ $computed.get = () => {
233
+ set();
234
+ return get();
235
+ };
236
+ let timer;
237
+ let run = batched ? () => {
238
+ clearTimeout(timer);
239
+ timer = setTimeout(set);
33
240
  } : set;
34
- return p(a, () => {
35
- let t = e.map((e) => e.listen(l));
36
- return set(), () => {
37
- for (let e of t) e();
241
+ onMount($computed, () => {
242
+ let unbinds = stores.map(($store) => $store.listen(run));
243
+ set();
244
+ return () => {
245
+ for (let unbind of unbinds) unbind();
38
246
  };
39
- }), a;
40
- }, batched = /* @__NO_SIDE_EFFECTS__ */ (e, t) => computedStore(e, t, !0), z = fe(null);
247
+ });
248
+ return $computed;
249
+ };
250
+ var batched = /* @__NO_SIDE_EFFECTS__ */ (stores, fn) => computedStore(stores, fn, true);
251
+ // src/aichat/ChatContext.tsx
252
+ var ChatContext = createContext(null);
41
253
  function useChatContext() {
42
- return _e(pe(z), "useChatContext: ChatProvider is not provided");
254
+ return nonNullable(use(ChatContext), "useChatContext: ChatProvider is not provided");
43
255
  }
44
- //#endregion
45
- //#region src/aichat/ChatInput.tsx
256
+ // src/aichat/ChatInput.tsx
46
257
  function ChatInput() {
47
- let e = F(22), { sendMessage: t, isLoading: n, messages: r, clear: i, stop: o } = useChatContext(), [s, c] = he(""), l = P(null), t0;
48
- e[0] !== n || e[1] !== t || e[2] !== s ? (t0 = () => {
49
- s.trim() && !n && (t(s), c(""));
50
- }, e[0] = n, e[1] = t, e[2] = s, e[3] = t0) : t0 = e[3];
51
- let u = t0, t1;
52
- e[4] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (e) => c(e.target.value), e[4] = t1) : t1 = e[4];
258
+ const $ = c(22);
259
+ const { sendMessage, isLoading, messages, clear, stop } = useChatContext();
260
+ const [value, setValue] = useState("");
261
+ const inputRef = useRef(null);
262
+ let t0;
263
+ if ($[0] !== isLoading || $[1] !== sendMessage || $[2] !== value) {
264
+ t0 = () => {
265
+ if (!value.trim() || isLoading) return;
266
+ sendMessage(value);
267
+ setValue("");
268
+ };
269
+ $[0] = isLoading;
270
+ $[1] = sendMessage;
271
+ $[2] = value;
272
+ $[3] = t0;
273
+ } else t0 = $[3];
274
+ const handleSubmit = t0;
275
+ let t1;
276
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
277
+ t1 = (e) => setValue(e.target.value);
278
+ $[4] = t1;
279
+ } else t1 = $[4];
53
280
  let t2;
54
- e[5] === u ? t2 = e[6] : (t2 = (e) => {
55
- e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && (e.preventDefault(), u());
56
- }, e[5] = u, e[6] = t2);
57
- let d;
58
- e[7] !== n || e[8] !== t2 || e[9] !== s ? (d = /* @__PURE__ */ L(_, {
59
- flex: 1,
60
- className: "chat-input",
61
- placeholder: "Your question...",
62
- value: s,
63
- onChange: t1,
64
- onKeyDown: t2,
65
- disabled: n,
66
- ref: l,
67
- loading: n,
68
- autosize: !0,
69
- minRows: 1
70
- }), e[7] = n, e[8] = t2, e[9] = s, e[10] = d) : d = e[10];
71
- let f;
72
- e[11] !== i || e[12] !== n || e[13] !== r.length ? (f = r.length > 0 && !n && /* @__PURE__ */ L(ee, {
73
- size: "sm",
74
- color: "red",
75
- variant: "light",
76
- onClick: () => i(),
77
- children: "Clear"
78
- }), e[11] = i, e[12] = n, e[13] = r.length, e[14] = f) : f = e[14];
79
- let p;
80
- e[15] !== n || e[16] !== o ? (p = n && /* @__PURE__ */ L(x, {
81
- color: "red",
82
- variant: "light",
83
- onClick: () => o(),
84
- children: /* @__PURE__ */ L(a, {})
85
- }), e[15] = n, e[16] = o, e[17] = p) : p = e[17];
86
- let m;
87
- return e[18] !== d || e[19] !== f || e[20] !== p ? (m = /* @__PURE__ */ R(S, { children: [
88
- d,
89
- f,
90
- p
91
- ] }), e[18] = d, e[19] = f, e[20] = p, e[21] = m) : m = e[21], m;
92
- }
93
- //#endregion
94
- //#region src/aichat/ChatMessage.tsx
281
+ if ($[5] !== handleSubmit) {
282
+ t2 = (e_0) => {
283
+ if (e_0.key === "Enter" && !e_0.shiftKey && !e_0.ctrlKey && !e_0.metaKey) {
284
+ e_0.preventDefault();
285
+ handleSubmit();
286
+ }
287
+ };
288
+ $[5] = handleSubmit;
289
+ $[6] = t2;
290
+ } else t2 = $[6];
291
+ let t3;
292
+ if ($[7] !== isLoading || $[8] !== t2 || $[9] !== value) {
293
+ t3 = /* @__PURE__ */ jsx(Textarea, {
294
+ flex: 1,
295
+ className: "chat-input",
296
+ placeholder: "Your question...",
297
+ value,
298
+ onChange: t1,
299
+ onKeyDown: t2,
300
+ disabled: isLoading,
301
+ ref: inputRef,
302
+ loading: isLoading,
303
+ autosize: true,
304
+ minRows: 1
305
+ });
306
+ $[7] = isLoading;
307
+ $[8] = t2;
308
+ $[9] = value;
309
+ $[10] = t3;
310
+ } else t3 = $[10];
311
+ let t4;
312
+ if ($[11] !== clear || $[12] !== isLoading || $[13] !== messages.length) {
313
+ t4 = messages.length > 0 && !isLoading && /* @__PURE__ */ jsx(Button, {
314
+ size: "sm",
315
+ color: "red",
316
+ variant: "light",
317
+ onClick: () => clear(),
318
+ children: "Clear"
319
+ });
320
+ $[11] = clear;
321
+ $[12] = isLoading;
322
+ $[13] = messages.length;
323
+ $[14] = t4;
324
+ } else t4 = $[14];
325
+ let t5;
326
+ if ($[15] !== isLoading || $[16] !== stop) {
327
+ t5 = isLoading && /* @__PURE__ */ jsx(ActionIcon, {
328
+ color: "red",
329
+ variant: "light",
330
+ onClick: () => stop(),
331
+ children: /* @__PURE__ */ jsx(IconPlayerStopFilled, {})
332
+ });
333
+ $[15] = isLoading;
334
+ $[16] = stop;
335
+ $[17] = t5;
336
+ } else t5 = $[17];
337
+ let t6;
338
+ if ($[18] !== t3 || $[19] !== t4 || $[20] !== t5) {
339
+ t6 = /* @__PURE__ */ jsxs(HStack, { children: [
340
+ t3,
341
+ t4,
342
+ t5
343
+ ] });
344
+ $[18] = t3;
345
+ $[19] = t4;
346
+ $[20] = t5;
347
+ $[21] = t6;
348
+ } else t6 = $[21];
349
+ return t6;
350
+ }
351
+ // src/aichat/ChatMessage.tsx
95
352
  function ChatMessages() {
96
- let e = F(7), { messages: t, error: n } = useChatContext(), r;
97
- e[0] === t ? r = e[1] : (r = t.map(_temp), e[0] = t, e[1] = r);
98
- let i;
99
- e[2] === n ? i = e[3] : (i = n && /* @__PURE__ */ L(y, {
100
- styles: { icon: { alignSelf: "flex-start" } },
101
- color: "red",
102
- title: "Oops, something went wrong",
103
- withCloseButton: !1,
104
- children: /* @__PURE__ */ R(T, {
105
- fontSize: "sm",
106
- fontFamily: "mono",
107
- whiteSpace: "pre",
108
- my: "xs",
109
- children: [n.message, n.stack && "\n" + n.stack]
110
- })
111
- }), e[2] = n, e[3] = i);
112
- let a;
113
- return e[4] !== r || e[5] !== i ? (a = /* @__PURE__ */ R(I, { children: [r, i] }), e[4] = r, e[5] = i, e[6] = a) : a = e[6], a;
114
- }
115
- function _temp(e) {
116
- return /* @__PURE__ */ L(ChatMessage, { message: e }, e.id);
117
- }
118
- var ChatMessage = (e) => {
119
- let t = F(4), { message: n } = e, r = n.role, i;
120
- t[0] === Symbol.for("react.memo_cache_sentinel") ? (i = C({
121
- color: "text.bright",
122
- alignSelf: "flex-end",
123
- paddingInline: "2",
124
- paddingBlock: "1",
125
- marginInlineEnd: "2",
126
- rounded: "sm",
127
- backgroundColor: "surface.hover",
128
- whiteSpace: "pre-wrap"
129
- }), t[0] = i) : i = t[0];
130
- let a = r === "user" ? UserMessageTextPart : MarkdownTextPart, o;
131
- return t[1] !== n || t[2] !== a ? (o = /* @__PURE__ */ L(de, {
132
- message: n,
133
- userClassName: i,
134
- textPartRenderer: a
135
- }), t[1] = n, t[2] = a, t[3] = o) : o = t[3], o;
136
- }, UserMessageTextPart = (e) => {
137
- let t = F(2), { content: n } = e, r;
138
- return t[0] === n ? r = t[1] : (r = /* @__PURE__ */ L(I, { children: n }), t[0] = n, t[1] = r), r;
139
- }, MarkdownTextPart = (e) => {
140
- let t = F(4), { content: n } = e, r;
141
- t[0] === n ? r = t[1] : (r = ge.from({ md: n }), t[0] = n, t[1] = r);
142
- let i;
143
- return t[2] === r ? i = t[3] : (i = /* @__PURE__ */ L(c, {
144
- textScale: .95,
145
- value: r
146
- }), t[2] = r, t[3] = i), i;
147
- }, B = /* @__PURE__ */ m(""), V = /* @__PURE__ */ m("closed"), xe = /* @__PURE__ */ batched([B, V], (e, t) => ({
148
- log: e,
149
- status: t
353
+ const $ = c(7);
354
+ const { messages, error } = useChatContext();
355
+ let t0;
356
+ if ($[0] !== messages) {
357
+ t0 = messages.map(_temp);
358
+ $[0] = messages;
359
+ $[1] = t0;
360
+ } else t0 = $[1];
361
+ let t1;
362
+ if ($[2] !== error) {
363
+ t1 = error && /* @__PURE__ */ jsx(Notification, {
364
+ styles: { icon: { alignSelf: "flex-start" } },
365
+ color: "red",
366
+ title: "Oops, something went wrong",
367
+ withCloseButton: false,
368
+ children: /* @__PURE__ */ jsxs(Txt, {
369
+ fontSize: "sm",
370
+ fontFamily: "mono",
371
+ whiteSpace: "pre",
372
+ my: "xs",
373
+ children: [error.message, error.stack && "\n" + error.stack]
374
+ })
375
+ });
376
+ $[2] = error;
377
+ $[3] = t1;
378
+ } else t1 = $[3];
379
+ let t2;
380
+ if ($[4] !== t0 || $[5] !== t1) {
381
+ t2 = /* @__PURE__ */ jsxs(Fragment, { children: [t0, t1] });
382
+ $[4] = t0;
383
+ $[5] = t1;
384
+ $[6] = t2;
385
+ } else t2 = $[6];
386
+ return t2;
387
+ }
388
+ function _temp(message) {
389
+ return /* @__PURE__ */ jsx(ChatMessage, { message }, message.id);
390
+ }
391
+ var ChatMessage = (t0) => {
392
+ const $ = c(4);
393
+ const { message } = t0;
394
+ const role = message.role;
395
+ let t1;
396
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
397
+ t1 = css({
398
+ color: "text.bright",
399
+ alignSelf: "flex-end",
400
+ paddingInline: "2",
401
+ paddingBlock: "1",
402
+ marginInlineEnd: "2",
403
+ rounded: "sm",
404
+ backgroundColor: "surface.hover",
405
+ whiteSpace: "pre-wrap"
406
+ });
407
+ $[0] = t1;
408
+ } else t1 = $[0];
409
+ const t2 = role === "user" ? UserMessageTextPart : MarkdownTextPart;
410
+ let t3;
411
+ if ($[1] !== message || $[2] !== t2) {
412
+ t3 = /* @__PURE__ */ jsx(ChatMessage$1, {
413
+ message,
414
+ userClassName: t1,
415
+ textPartRenderer: t2
416
+ });
417
+ $[1] = message;
418
+ $[2] = t2;
419
+ $[3] = t3;
420
+ } else t3 = $[3];
421
+ return t3;
422
+ };
423
+ var UserMessageTextPart = (t0) => {
424
+ const $ = c(2);
425
+ const { content } = t0;
426
+ let t1;
427
+ if ($[0] !== content) {
428
+ t1 = /* @__PURE__ */ jsx(Fragment, { children: content });
429
+ $[0] = content;
430
+ $[1] = t1;
431
+ } else t1 = $[1];
432
+ return t1;
433
+ };
434
+ var MarkdownTextPart = (t0) => {
435
+ const $ = c(4);
436
+ const { content } = t0;
437
+ let t1;
438
+ if ($[0] !== content) {
439
+ t1 = RichText.from({ md: content });
440
+ $[0] = content;
441
+ $[1] = t1;
442
+ } else t1 = $[1];
443
+ let t2;
444
+ if ($[2] !== t1) {
445
+ t2 = /* @__PURE__ */ jsx(Markdown, {
446
+ textScale: .95,
447
+ value: t1
448
+ });
449
+ $[2] = t1;
450
+ $[3] = t2;
451
+ } else t2 = $[3];
452
+ return t2;
453
+ };
454
+ // src/aichat/semantic-layout-log-state.ts
455
+ var $log = /* @__PURE__ */ atom("");
456
+ var $status = /* @__PURE__ */ atom("closed");
457
+ var $state = /* @__PURE__ */ batched([$log, $status], (log, status) => ({
458
+ log,
459
+ status
150
460
  }));
151
461
  function useSemanticLayoutLog() {
152
- return o(xe);
462
+ return useStore($state);
153
463
  }
154
464
  function closeSemanticLayoutLog() {
155
- V.set("closed"), B.set("");
465
+ $status.set("closed");
466
+ $log.set("");
156
467
  }
157
- //#endregion
158
- //#region src/aichat/SemanticLayoutLog.tsx
468
+ // src/aichat/SemanticLayoutLog.tsx
469
+ /**
470
+ * Modal that shows the log of the semantic layout application
471
+ * (For internal debugging purposes)
472
+ */
159
473
  function SemanticLayoutLog() {
160
- let e = F(6), { log: t, status: n } = useSemanticLayoutLog();
161
- if (n === "closed") return null;
162
- let r = n === "completed", i;
163
- e[0] === Symbol.for("react.memo_cache_sentinel") ? (i = /* @__PURE__ */ L(re, {
164
- order: 4,
165
- children: "Semantic Layout"
166
- }), e[0] = i) : i = e[0];
167
- let a = t || "Waiting for response...", o;
168
- e[1] === a ? o = e[2] : (o = /* @__PURE__ */ L(T, {
169
- whiteSpace: "pre-wrap",
170
- children: a
171
- }), e[1] = a, e[2] = o);
172
- let s;
173
- return e[3] !== r || e[4] !== o ? (s = /* @__PURE__ */ L(g, {
174
- size: "xl",
175
- opened: !0,
176
- onClose: closeSemanticLayoutLog,
177
- closeOnEscape: r,
178
- withCloseButton: r,
179
- closeOnClickOutside: r,
180
- title: i,
181
- children: o
182
- }), e[3] = r, e[4] = o, e[5] = s) : s = e[5], s;
183
- }
184
- //#endregion
185
- //#region ../vite-plugin/src/ai/tools.ts
186
- var H = j({
187
- id: D().meta({ description: "Node ID" }),
188
- title: D(),
189
- shape: M(ye),
190
- color: D().meta({ description: "Node color, from theme or custom" }),
191
- icon: D().nullish(),
192
- parentId: D().nullish().meta({ description: "Parent node ID (if node is nested)" }),
193
- children: O(D()).nullish().meta({ description: "Nested node IDs (if node is compound)" }),
194
- x: k(),
195
- y: k(),
196
- width: k(),
197
- height: k(),
198
- modelFqn: D().nullish().meta({ description: "Model element FQN (if node has reference)" })
199
- }), Se = N({
474
+ const $ = c(6);
475
+ const { log, status } = useSemanticLayoutLog();
476
+ if (status === "closed") return null;
477
+ const closable = status === "completed";
478
+ let t0;
479
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
480
+ t0 = /* @__PURE__ */ jsx(Title, {
481
+ order: 4,
482
+ children: "Semantic Layout"
483
+ });
484
+ $[0] = t0;
485
+ } else t0 = $[0];
486
+ const t1 = log || "Waiting for response...";
487
+ let t2;
488
+ if ($[1] !== t1) {
489
+ t2 = /* @__PURE__ */ jsx(Txt, {
490
+ whiteSpace: "pre-wrap",
491
+ children: t1
492
+ });
493
+ $[1] = t1;
494
+ $[2] = t2;
495
+ } else t2 = $[2];
496
+ let t3;
497
+ if ($[3] !== closable || $[4] !== t2) {
498
+ t3 = /* @__PURE__ */ jsx(Modal, {
499
+ size: "xl",
500
+ opened: true,
501
+ onClose: closeSemanticLayoutLog,
502
+ closeOnEscape: closable,
503
+ withCloseButton: closable,
504
+ closeOnClickOutside: closable,
505
+ title: t0,
506
+ children: t2
507
+ });
508
+ $[3] = closable;
509
+ $[4] = t2;
510
+ $[5] = t3;
511
+ } else t3 = $[5];
512
+ return t3;
513
+ }
514
+ // ../vite-plugin/src/ai/tools.ts
515
+ var nodeSchema = z.object({
516
+ id: z.string().meta({ description: "Node ID" }),
517
+ title: z.string(),
518
+ shape: z.enum(ElementShapes),
519
+ color: z.string().meta({ description: "Node color, from theme or custom" }),
520
+ icon: z.string().nullish(),
521
+ parentId: z.string().nullish().meta({ description: "Parent node ID (if node is nested)" }),
522
+ children: z.array(z.string()).nullish().meta({ description: "Nested node IDs (if node is compound)" }),
523
+ x: z.number(),
524
+ y: z.number(),
525
+ width: z.number(),
526
+ height: z.number(),
527
+ modelFqn: z.string().nullish().meta({ description: "Model element FQN (if node has reference)" })
528
+ });
529
+ var readUiStateDef = toolDefinition({
200
530
  name: "read_ui",
201
531
  description: "Read current UI state. Use arguments to include additional data.",
202
- needsApproval: !1,
203
- inputSchema: j({
204
- selectedNode: A().default(!1).meta({ description: "Include selected node (if any)" }),
205
- nodes: A().default(!1).meta({ description: "Include all nodes from the view" })
532
+ needsApproval: false,
533
+ inputSchema: z.object({
534
+ selectedNode: z.boolean().default(false).meta({ description: "Include selected node (if any)" }),
535
+ nodes: z.boolean().default(false).meta({ description: "Include all nodes from the view" })
206
536
  }),
207
- outputSchema: j({
208
- projectId: D(),
209
- editMode: A().meta({ description: "Whether the UI is in edit mode" }),
210
- view: j({
211
- id: D(),
212
- title: D(),
213
- type: M([
537
+ outputSchema: z.object({
538
+ projectId: z.string(),
539
+ editMode: z.boolean().meta({ description: "Whether the UI is in edit mode" }),
540
+ view: z.object({
541
+ id: z.string(),
542
+ title: z.string(),
543
+ type: z.enum([
214
544
  "element",
215
545
  "deployment",
216
546
  "dynamic"
217
547
  ]).meta({ description: "Type of the current view" })
218
548
  }).meta({ description: "Current view" }),
219
- nodes: O(H).nullish(),
220
- selectedNode: H.nullish()
549
+ nodes: z.array(nodeSchema).nullish(),
550
+ selectedNode: nodeSchema.nullish()
221
551
  })
222
- }), Ce = j({
223
- type: E("focus"),
224
- elementId: D().meta({ description: "Element ID (FQN)" })
225
- }).meta({ description: "Focus UI on an element by its FQN" }), we = j({ type: E("fitview") }).meta({ description: "Zoom out to fit all elements in the viewport, and clear any selection/focus" }), Te = N({
552
+ });
553
+ var focusCommand = z.object({
554
+ type: z.literal("focus"),
555
+ elementId: z.string().meta({ description: "Element ID (FQN)" })
556
+ }).meta({ description: "Focus UI on an element by its FQN" });
557
+ var fitViewCommand = z.object({ type: z.literal("fitview") }).meta({ description: "Zoom out to fit all elements in the viewport, and clear any selection/focus" });
558
+ var updateUiStateDef = toolDefinition({
226
559
  name: "update_ui",
227
560
  description: "Update UI state by executing a command.",
228
- needsApproval: !1,
229
- inputSchema: j({ command: se("type", [Ce, we]) }),
230
- outputSchema: j({})
231
- }), Ee = N({
561
+ needsApproval: false,
562
+ inputSchema: z.object({ command: z.discriminatedUnion("type", [focusCommand, fitViewCommand]) }),
563
+ outputSchema: z.object({})
564
+ });
565
+ var navigateToDef = toolDefinition({
232
566
  name: "navigate_to",
233
567
  description: "Navigates UI to another view",
234
- needsApproval: !1,
235
- inputSchema: j({ viewId: D().meta({ description: "View ID" }) }),
236
- outputSchema: j({})
237
- }), DoubleIndexedKV = class {
568
+ needsApproval: false,
569
+ inputSchema: z.object({ viewId: z.string().meta({ description: "View ID" }) }),
570
+ outputSchema: z.object({})
571
+ });
572
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/double-indexed-kv.js
573
+ var DoubleIndexedKV = class {
238
574
  constructor() {
239
- this.keyToValue = /* @__PURE__ */ new Map(), this.valueToKey = /* @__PURE__ */ new Map();
575
+ this.keyToValue = /* @__PURE__ */ new Map();
576
+ this.valueToKey = /* @__PURE__ */ new Map();
240
577
  }
241
- set(e, t) {
242
- this.keyToValue.set(e, t), this.valueToKey.set(t, e);
578
+ set(key, value) {
579
+ this.keyToValue.set(key, value);
580
+ this.valueToKey.set(value, key);
243
581
  }
244
- getByKey(e) {
245
- return this.keyToValue.get(e);
582
+ getByKey(key) {
583
+ return this.keyToValue.get(key);
246
584
  }
247
- getByValue(e) {
248
- return this.valueToKey.get(e);
585
+ getByValue(value) {
586
+ return this.valueToKey.get(value);
249
587
  }
250
588
  clear() {
251
- this.keyToValue.clear(), this.valueToKey.clear();
589
+ this.keyToValue.clear();
590
+ this.valueToKey.clear();
252
591
  }
253
- }, Registry = class {
254
- constructor(e) {
255
- this.generateIdentifier = e, this.kv = new DoubleIndexedKV();
592
+ };
593
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/registry.js
594
+ var Registry = class {
595
+ constructor(generateIdentifier) {
596
+ this.generateIdentifier = generateIdentifier;
597
+ this.kv = new DoubleIndexedKV();
256
598
  }
257
- register(e, t) {
258
- this.kv.getByValue(e) || (t ||= this.generateIdentifier(e), this.kv.set(t, e));
599
+ register(value, identifier) {
600
+ if (this.kv.getByValue(value)) return;
601
+ if (!identifier) identifier = this.generateIdentifier(value);
602
+ this.kv.set(identifier, value);
259
603
  }
260
604
  clear() {
261
605
  this.kv.clear();
262
606
  }
263
- getIdentifier(e) {
264
- return this.kv.getByValue(e);
607
+ getIdentifier(value) {
608
+ return this.kv.getByValue(value);
265
609
  }
266
- getValue(e) {
267
- return this.kv.getByKey(e);
610
+ getValue(identifier) {
611
+ return this.kv.getByKey(identifier);
268
612
  }
269
- }, ClassRegistry = class extends Registry {
613
+ };
614
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/class-registry.js
615
+ var ClassRegistry = class extends Registry {
270
616
  constructor() {
271
- super((e) => e.name), this.classToAllowedProps = /* @__PURE__ */ new Map();
617
+ super((c) => c.name);
618
+ this.classToAllowedProps = /* @__PURE__ */ new Map();
272
619
  }
273
- register(e, t) {
274
- typeof t == "object" ? (t.allowProps && this.classToAllowedProps.set(e, t.allowProps), super.register(e, t.identifier)) : super.register(e, t);
620
+ register(value, options) {
621
+ if (typeof options === "object") {
622
+ if (options.allowProps) this.classToAllowedProps.set(value, options.allowProps);
623
+ super.register(value, options.identifier);
624
+ } else super.register(value, options);
275
625
  }
276
- getAllowedProps(e) {
277
- return this.classToAllowedProps.get(e);
626
+ getAllowedProps(value) {
627
+ return this.classToAllowedProps.get(value);
278
628
  }
279
629
  };
280
- //#endregion
281
- //#region ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/util.js
282
- function valuesOfObj(e) {
283
- if ("values" in Object) return Object.values(e);
284
- let t = [];
285
- for (let n in e) e.hasOwnProperty(n) && t.push(e[n]);
286
- return t;
630
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/util.js
631
+ function valuesOfObj(record) {
632
+ if ("values" in Object) return Object.values(record);
633
+ const values = [];
634
+ for (const key in record) if (record.hasOwnProperty(key)) values.push(record[key]);
635
+ return values;
287
636
  }
288
- function find(e, t) {
289
- let n = valuesOfObj(e);
290
- if ("find" in n) return n.find(t);
291
- let r = n;
292
- for (let e = 0; e < r.length; e++) {
293
- let n = r[e];
294
- if (t(n)) return n;
637
+ function find(record, predicate) {
638
+ const values = valuesOfObj(record);
639
+ if ("find" in values) return values.find(predicate);
640
+ const valuesNotNever = values;
641
+ for (let i = 0; i < valuesNotNever.length; i++) {
642
+ const value = valuesNotNever[i];
643
+ if (predicate(value)) return value;
295
644
  }
296
645
  }
297
- function forEach(e, t) {
298
- Object.entries(e).forEach(([e, n]) => t(n, e));
646
+ function forEach(record, run) {
647
+ Object.entries(record).forEach(([key, value]) => run(value, key));
299
648
  }
300
- function includes(e, t) {
301
- return e.indexOf(t) !== -1;
649
+ function includes(arr, value) {
650
+ return arr.indexOf(value) !== -1;
302
651
  }
303
- function findArr(e, t) {
304
- for (let n = 0; n < e.length; n++) {
305
- let r = e[n];
306
- if (t(r)) return r;
652
+ function findArr(record, predicate) {
653
+ for (let i = 0; i < record.length; i++) {
654
+ const value = record[i];
655
+ if (predicate(value)) return value;
307
656
  }
308
657
  }
309
- //#endregion
310
- //#region ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/custom-transformer-registry.js
658
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/custom-transformer-registry.js
311
659
  var CustomTransformerRegistry = class {
312
660
  constructor() {
313
661
  this.transfomers = {};
314
662
  }
315
- register(e) {
316
- this.transfomers[e.name] = e;
663
+ register(transformer) {
664
+ this.transfomers[transformer.name] = transformer;
317
665
  }
318
- findApplicable(e) {
319
- return find(this.transfomers, (t) => t.isApplicable(e));
666
+ findApplicable(v) {
667
+ return find(this.transfomers, (transformer) => transformer.isApplicable(v));
320
668
  }
321
- findByName(e) {
322
- return this.transfomers[e];
669
+ findByName(name) {
670
+ return this.transfomers[name];
323
671
  }
324
- }, De = /* @__PURE__ */ e((e) => Object.prototype.toString.call(e).slice(8, -1), "getType"), isUndefined = (e) => e === void 0, isNull = (e) => e === null, U = /* @__PURE__ */ e((e) => typeof e != "object" || !e || e === Object.prototype ? !1 : Object.getPrototypeOf(e) === null || Object.getPrototypeOf(e) === Object.prototype, "isPlainObject"), isEmptyObject = (e) => U(e) && Object.keys(e).length === 0, W = /* @__PURE__ */ e((e) => Array.isArray(e), "isArray"), isString = (e) => typeof e == "string", isNumber = (e) => typeof e == "number" && !isNaN(e), isBoolean = (e) => typeof e == "boolean", isRegExp = (e) => e instanceof RegExp, isMap = (e) => e instanceof Map, isSet = (e) => e instanceof Set, isSymbol = (e) => De(e) === "Symbol", isDate = (e) => e instanceof Date && !isNaN(e.valueOf()), isError = (e) => e instanceof Error, isNaNValue = (e) => typeof e == "number" && isNaN(e), isPrimitive = (e) => isBoolean(e) || isNull(e) || isUndefined(e) || isNumber(e) || isString(e) || isSymbol(e), isBigint = (e) => typeof e == "bigint", isInfinite = (e) => e === Infinity || e === -Infinity, isTypedArray = (e) => ArrayBuffer.isView(e) && !(e instanceof DataView), isURL = (e) => e instanceof URL, escapeKey = (e) => e.replace(/\\/g, "\\\\").replace(/\./g, "\\."), stringifyPath = (e) => e.map(String).map(escapeKey).join("."), parsePath = (e, t) => {
325
- let n = [], r = "";
326
- for (let i = 0; i < e.length; i++) {
327
- let a = e.charAt(i);
328
- if (!t && a === "\\") {
329
- let t = e.charAt(i + 1);
330
- if (t === "\\") {
331
- r += "\\", i++;
672
+ };
673
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/is.js
674
+ var getType$1 = /* @__PURE__ */ __name((payload) => Object.prototype.toString.call(payload).slice(8, -1), "getType");
675
+ var isUndefined = (payload) => typeof payload === "undefined";
676
+ var isNull = (payload) => payload === null;
677
+ var isPlainObject$1 = /* @__PURE__ */ __name((payload) => {
678
+ if (typeof payload !== "object" || payload === null) return false;
679
+ if (payload === Object.prototype) return false;
680
+ if (Object.getPrototypeOf(payload) === null) return true;
681
+ return Object.getPrototypeOf(payload) === Object.prototype;
682
+ }, "isPlainObject");
683
+ var isEmptyObject = (payload) => isPlainObject$1(payload) && Object.keys(payload).length === 0;
684
+ var isArray$1 = /* @__PURE__ */ __name((payload) => Array.isArray(payload), "isArray");
685
+ var isString = (payload) => typeof payload === "string";
686
+ var isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
687
+ var isBoolean = (payload) => typeof payload === "boolean";
688
+ var isRegExp = (payload) => payload instanceof RegExp;
689
+ var isMap = (payload) => payload instanceof Map;
690
+ var isSet = (payload) => payload instanceof Set;
691
+ var isSymbol = (payload) => getType$1(payload) === "Symbol";
692
+ var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
693
+ var isError = (payload) => payload instanceof Error;
694
+ var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
695
+ var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
696
+ var isBigint = (payload) => typeof payload === "bigint";
697
+ var isInfinite = (payload) => payload === Infinity || payload === -Infinity;
698
+ var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
699
+ var isURL = (payload) => payload instanceof URL;
700
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/pathstringifier.js
701
+ var escapeKey = (key) => key.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
702
+ var stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
703
+ var parsePath = (string, legacyPaths) => {
704
+ const result = [];
705
+ let segment = "";
706
+ for (let i = 0; i < string.length; i++) {
707
+ let char = string.charAt(i);
708
+ if (!legacyPaths && char === "\\") {
709
+ const escaped = string.charAt(i + 1);
710
+ if (escaped === "\\") {
711
+ segment += "\\";
712
+ i++;
332
713
  continue;
333
- }
334
- if (t !== ".") throw Error("invalid path");
714
+ } else if (escaped !== ".") throw Error("invalid path");
335
715
  }
336
- if (a === "\\" && e.charAt(i + 1) === ".") {
337
- r += ".", i++;
716
+ if (char === "\\" && string.charAt(i + 1) === ".") {
717
+ segment += ".";
718
+ i++;
338
719
  continue;
339
720
  }
340
- if (a === ".") {
341
- n.push(r), r = "";
721
+ if (char === ".") {
722
+ result.push(segment);
723
+ segment = "";
342
724
  continue;
343
725
  }
344
- r += a;
726
+ segment += char;
345
727
  }
346
- let i = r;
347
- return n.push(i), n;
728
+ const lastSegment = segment;
729
+ result.push(lastSegment);
730
+ return result;
348
731
  };
349
- //#endregion
350
- //#region ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/transformer.js
351
- function simpleTransformation(e, t, n, r) {
732
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/transformer.js
733
+ function simpleTransformation(isApplicable, annotation, transform, untransform) {
352
734
  return {
353
- isApplicable: e,
354
- annotation: t,
355
- transform: n,
356
- untransform: r
735
+ isApplicable,
736
+ annotation,
737
+ transform,
738
+ untransform
357
739
  };
358
740
  }
359
- var G = [
741
+ var simpleRules = [
360
742
  simpleTransformation(isUndefined, "undefined", () => null, () => void 0),
361
- simpleTransformation(isBigint, "bigint", (e) => e.toString(), (e) => typeof BigInt < "u" ? BigInt(e) : (console.error("Please add a BigInt polyfill."), e)),
362
- simpleTransformation(isDate, "Date", (e) => e.toISOString(), (e) => new Date(e)),
363
- simpleTransformation(isError, "Error", (e, t) => {
364
- let n = {
365
- name: e.name,
366
- message: e.message
743
+ simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
744
+ if (typeof BigInt !== "undefined") return BigInt(v);
745
+ console.error("Please add a BigInt polyfill.");
746
+ return v;
747
+ }),
748
+ simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
749
+ simpleTransformation(isError, "Error", (v, superJson) => {
750
+ const baseError = {
751
+ name: v.name,
752
+ message: v.message
367
753
  };
368
- return "cause" in e && (n.cause = e.cause), t.allowedErrorProps.forEach((t) => {
369
- n[t] = e[t];
370
- }), n;
371
- }, (e, t) => {
372
- let n = Error(e.message, { cause: e.cause });
373
- return n.name = e.name, n.stack = e.stack, t.allowedErrorProps.forEach((t) => {
374
- n[t] = e[t];
375
- }), n;
754
+ if ("cause" in v) baseError.cause = v.cause;
755
+ superJson.allowedErrorProps.forEach((prop) => {
756
+ baseError[prop] = v[prop];
757
+ });
758
+ return baseError;
759
+ }, (v, superJson) => {
760
+ const e = new Error(v.message, { cause: v.cause });
761
+ e.name = v.name;
762
+ e.stack = v.stack;
763
+ superJson.allowedErrorProps.forEach((prop) => {
764
+ e[prop] = v[prop];
765
+ });
766
+ return e;
376
767
  }),
377
- simpleTransformation(isRegExp, "regexp", (e) => "" + e, (e) => {
378
- let t = e.slice(1, e.lastIndexOf("/")), n = e.slice(e.lastIndexOf("/") + 1);
379
- return new RegExp(t, n);
768
+ simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
769
+ const body = regex.slice(1, regex.lastIndexOf("/"));
770
+ const flags = regex.slice(regex.lastIndexOf("/") + 1);
771
+ return new RegExp(body, flags);
380
772
  }),
381
- simpleTransformation(isSet, "set", (e) => [...e.values()], (e) => new Set(e)),
382
- simpleTransformation(isMap, "map", (e) => [...e.entries()], (e) => new Map(e)),
383
- simpleTransformation((e) => isNaNValue(e) || isInfinite(e), "number", (e) => isNaNValue(e) ? "NaN" : e > 0 ? "Infinity" : "-Infinity", Number),
384
- simpleTransformation((e) => e === 0 && 1 / e == -Infinity, "number", () => "-0", Number),
385
- simpleTransformation(isURL, "URL", (e) => e.toString(), (e) => new URL(e))
773
+ simpleTransformation(isSet, "set", (v) => [...v.values()], (v) => new Set(v)),
774
+ simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
775
+ simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
776
+ if (isNaNValue(v)) return "NaN";
777
+ if (v > 0) return "Infinity";
778
+ else return "-Infinity";
779
+ }, Number),
780
+ simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
781
+ return "-0";
782
+ }, Number),
783
+ simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
386
784
  ];
387
- function compositeTransformation(e, t, n, r) {
785
+ function compositeTransformation(isApplicable, annotation, transform, untransform) {
388
786
  return {
389
- isApplicable: e,
390
- annotation: t,
391
- transform: n,
392
- untransform: r
787
+ isApplicable,
788
+ annotation,
789
+ transform,
790
+ untransform
393
791
  };
394
792
  }
395
- var K = compositeTransformation((e, t) => isSymbol(e) ? !!t.symbolRegistry.getIdentifier(e) : !1, (e, t) => ["symbol", t.symbolRegistry.getIdentifier(e)], (e) => e.description, (e, t, n) => {
396
- let r = n.symbolRegistry.getValue(t[1]);
397
- if (!r) throw Error("Trying to deserialize unknown symbol");
398
- return r;
399
- }), q = [
793
+ var symbolRule = compositeTransformation((s, superJson) => {
794
+ if (isSymbol(s)) return !!superJson.symbolRegistry.getIdentifier(s);
795
+ return false;
796
+ }, (s, superJson) => {
797
+ return ["symbol", superJson.symbolRegistry.getIdentifier(s)];
798
+ }, (v) => v.description, (_, a, superJson) => {
799
+ const value = superJson.symbolRegistry.getValue(a[1]);
800
+ if (!value) throw new Error("Trying to deserialize unknown symbol");
801
+ return value;
802
+ });
803
+ var constructorToName = [
400
804
  Int8Array,
401
805
  Uint8Array,
402
806
  Int16Array,
@@ -406,451 +810,616 @@ var K = compositeTransformation((e, t) => isSymbol(e) ? !!t.symbolRegistry.getId
406
810
  Float32Array,
407
811
  Float64Array,
408
812
  Uint8ClampedArray
409
- ].reduce((e, t) => (e[t.name] = t, e), {}), J = compositeTransformation(isTypedArray, (e) => ["typed-array", e.constructor.name], (e) => [...e], (e, t) => {
410
- let n = q[t[1]];
411
- if (!n) throw Error("Trying to deserialize unknown typed array");
412
- return new n(e);
813
+ ].reduce((obj, ctor) => {
814
+ obj[ctor.name] = ctor;
815
+ return obj;
816
+ }, {});
817
+ var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
818
+ const ctor = constructorToName[a[1]];
819
+ if (!ctor) throw new Error("Trying to deserialize unknown typed array");
820
+ return new ctor(v);
821
+ });
822
+ function isInstanceOfRegisteredClass(potentialClass, superJson) {
823
+ if (potentialClass?.constructor) return !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
824
+ return false;
825
+ }
826
+ var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
827
+ return ["class", superJson.classRegistry.getIdentifier(clazz.constructor)];
828
+ }, (clazz, superJson) => {
829
+ const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
830
+ if (!allowedProps) return { ...clazz };
831
+ const result = {};
832
+ allowedProps.forEach((prop) => {
833
+ result[prop] = clazz[prop];
834
+ });
835
+ return result;
836
+ }, (v, a, superJson) => {
837
+ const clazz = superJson.classRegistry.getValue(a[1]);
838
+ if (!clazz) throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
839
+ return Object.assign(Object.create(clazz.prototype), v);
840
+ });
841
+ var customRule = compositeTransformation((value, superJson) => {
842
+ return !!superJson.customTransformerRegistry.findApplicable(value);
843
+ }, (value, superJson) => {
844
+ return ["custom", superJson.customTransformerRegistry.findApplicable(value).name];
845
+ }, (value, superJson) => {
846
+ return superJson.customTransformerRegistry.findApplicable(value).serialize(value);
847
+ }, (v, a, superJson) => {
848
+ const transformer = superJson.customTransformerRegistry.findByName(a[1]);
849
+ if (!transformer) throw new Error("Trying to deserialize unknown custom value");
850
+ return transformer.deserialize(v);
413
851
  });
414
- function isInstanceOfRegisteredClass(e, t) {
415
- return e?.constructor ? !!t.classRegistry.getIdentifier(e.constructor) : !1;
416
- }
417
- var Y = compositeTransformation(isInstanceOfRegisteredClass, (e, t) => ["class", t.classRegistry.getIdentifier(e.constructor)], (e, t) => {
418
- let n = t.classRegistry.getAllowedProps(e.constructor);
419
- if (!n) return { ...e };
420
- let r = {};
421
- return n.forEach((t) => {
422
- r[t] = e[t];
423
- }), r;
424
- }, (e, t, n) => {
425
- let r = n.classRegistry.getValue(t[1]);
426
- if (!r) throw Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
427
- return Object.assign(Object.create(r.prototype), e);
428
- }), X = compositeTransformation((e, t) => !!t.customTransformerRegistry.findApplicable(e), (e, t) => ["custom", t.customTransformerRegistry.findApplicable(e).name], (e, t) => t.customTransformerRegistry.findApplicable(e).serialize(e), (e, t, n) => {
429
- let r = n.customTransformerRegistry.findByName(t[1]);
430
- if (!r) throw Error("Trying to deserialize unknown custom value");
431
- return r.deserialize(e);
432
- }), Oe = [
433
- Y,
434
- K,
435
- X,
436
- J
437
- ], transformValue = (e, t) => {
438
- let n = findArr(Oe, (n) => n.isApplicable(e, t));
439
- if (n) return {
440
- value: n.transform(e, t),
441
- type: n.annotation(e, t)
852
+ var compositeRules = [
853
+ classRule,
854
+ symbolRule,
855
+ customRule,
856
+ typedArrayRule
857
+ ];
858
+ var transformValue = (value, superJson) => {
859
+ const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
860
+ if (applicableCompositeRule) return {
861
+ value: applicableCompositeRule.transform(value, superJson),
862
+ type: applicableCompositeRule.annotation(value, superJson)
442
863
  };
443
- let r = findArr(G, (n) => n.isApplicable(e, t));
444
- if (r) return {
445
- value: r.transform(e, t),
446
- type: r.annotation
864
+ const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
865
+ if (applicableSimpleRule) return {
866
+ value: applicableSimpleRule.transform(value, superJson),
867
+ type: applicableSimpleRule.annotation
447
868
  };
448
- }, Z = {};
449
- G.forEach((e) => {
450
- Z[e.annotation] = e;
869
+ };
870
+ var simpleRulesByAnnotation = {};
871
+ simpleRules.forEach((rule) => {
872
+ simpleRulesByAnnotation[rule.annotation] = rule;
451
873
  });
452
- var untransformValue = (e, t, n) => {
453
- if (W(t)) switch (t[0]) {
454
- case "symbol": return K.untransform(e, t, n);
455
- case "class": return Y.untransform(e, t, n);
456
- case "custom": return X.untransform(e, t, n);
457
- case "typed-array": return J.untransform(e, t, n);
458
- default: throw Error("Unknown transformation: " + t);
874
+ var untransformValue = (json, type, superJson) => {
875
+ if (isArray$1(type)) switch (type[0]) {
876
+ case "symbol": return symbolRule.untransform(json, type, superJson);
877
+ case "class": return classRule.untransform(json, type, superJson);
878
+ case "custom": return customRule.untransform(json, type, superJson);
879
+ case "typed-array": return typedArrayRule.untransform(json, type, superJson);
880
+ default: throw new Error("Unknown transformation: " + type);
459
881
  }
460
882
  else {
461
- let r = Z[t];
462
- if (!r) throw Error("Unknown transformation: " + t);
463
- return r.untransform(e, n);
464
- }
465
- }, getNthKey = (e, t) => {
466
- if (t > e.size) throw Error("index out of bounds");
467
- let n = e.keys();
468
- for (; t > 0;) n.next(), t--;
469
- return n.next().value;
883
+ const transformation = simpleRulesByAnnotation[type];
884
+ if (!transformation) throw new Error("Unknown transformation: " + type);
885
+ return transformation.untransform(json, superJson);
886
+ }
887
+ };
888
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/accessDeep.js
889
+ var getNthKey = (value, n) => {
890
+ if (n > value.size) throw new Error("index out of bounds");
891
+ const keys = value.keys();
892
+ while (n > 0) {
893
+ keys.next();
894
+ n--;
895
+ }
896
+ return keys.next().value;
470
897
  };
471
- function validatePath(e) {
472
- if (includes(e, "__proto__")) throw Error("__proto__ is not allowed as a property");
473
- if (includes(e, "prototype")) throw Error("prototype is not allowed as a property");
474
- if (includes(e, "constructor")) throw Error("constructor is not allowed as a property");
475
- }
476
- var getDeep = (e, t) => {
477
- validatePath(t);
478
- for (let n = 0; n < t.length; n++) {
479
- let r = t[n];
480
- if (isSet(e)) e = getNthKey(e, +r);
481
- else if (isMap(e)) {
482
- let i = +r, a = +t[++n] == 0 ? "key" : "value", o = getNthKey(e, i);
483
- switch (a) {
898
+ function validatePath(path) {
899
+ if (includes(path, "__proto__")) throw new Error("__proto__ is not allowed as a property");
900
+ if (includes(path, "prototype")) throw new Error("prototype is not allowed as a property");
901
+ if (includes(path, "constructor")) throw new Error("constructor is not allowed as a property");
902
+ }
903
+ var getDeep = (object, path) => {
904
+ validatePath(path);
905
+ for (let i = 0; i < path.length; i++) {
906
+ const key = path[i];
907
+ if (isSet(object)) object = getNthKey(object, +key);
908
+ else if (isMap(object)) {
909
+ const row = +key;
910
+ const type = +path[++i] === 0 ? "key" : "value";
911
+ const keyOfRow = getNthKey(object, row);
912
+ switch (type) {
484
913
  case "key":
485
- e = o;
914
+ object = keyOfRow;
486
915
  break;
487
- case "value": e = e.get(o);
916
+ case "value": object = object.get(keyOfRow);
488
917
  }
489
- } else e = e[r];
490
- }
491
- return e;
492
- }, setDeep = (e, t, n) => {
493
- if (validatePath(t), t.length === 0) return n(e);
494
- let r = e;
495
- for (let e = 0; e < t.length - 1; e++) {
496
- let n = t[e];
497
- if (W(r)) {
498
- let e = +n;
499
- r = r[e];
500
- } else if (U(r)) r = r[n];
501
- else if (isSet(r)) {
502
- let e = +n;
503
- r = getNthKey(r, e);
504
- } else if (isMap(r)) {
505
- if (e === t.length - 2) break;
506
- let i = +n, a = +t[++e] == 0 ? "key" : "value", o = getNthKey(r, i);
507
- switch (a) {
918
+ } else object = object[key];
919
+ }
920
+ return object;
921
+ };
922
+ var setDeep = (object, path, mapper) => {
923
+ validatePath(path);
924
+ if (path.length === 0) return mapper(object);
925
+ let parent = object;
926
+ for (let i = 0; i < path.length - 1; i++) {
927
+ const key = path[i];
928
+ if (isArray$1(parent)) {
929
+ const index = +key;
930
+ parent = parent[index];
931
+ } else if (isPlainObject$1(parent)) parent = parent[key];
932
+ else if (isSet(parent)) {
933
+ const row = +key;
934
+ parent = getNthKey(parent, row);
935
+ } else if (isMap(parent)) {
936
+ if (i === path.length - 2) break;
937
+ const row = +key;
938
+ const type = +path[++i] === 0 ? "key" : "value";
939
+ const keyOfRow = getNthKey(parent, row);
940
+ switch (type) {
508
941
  case "key":
509
- r = o;
942
+ parent = keyOfRow;
510
943
  break;
511
- case "value": r = r.get(o);
944
+ case "value": parent = parent.get(keyOfRow);
512
945
  }
513
946
  }
514
947
  }
515
- let i = t[t.length - 1];
516
- if (W(r) ? r[+i] = n(r[+i]) : U(r) && (r[i] = n(r[i])), isSet(r)) {
517
- let e = getNthKey(r, +i), t = n(e);
518
- e !== t && (r.delete(e), r.add(t));
948
+ const lastKey = path[path.length - 1];
949
+ if (isArray$1(parent)) parent[+lastKey] = mapper(parent[+lastKey]);
950
+ else if (isPlainObject$1(parent)) parent[lastKey] = mapper(parent[lastKey]);
951
+ if (isSet(parent)) {
952
+ const oldValue = getNthKey(parent, +lastKey);
953
+ const newValue = mapper(oldValue);
954
+ if (oldValue !== newValue) {
955
+ parent.delete(oldValue);
956
+ parent.add(newValue);
957
+ }
519
958
  }
520
- if (isMap(r)) {
521
- let e = +t[t.length - 2], a = getNthKey(r, e);
522
- switch (+i == 0 ? "key" : "value") {
959
+ if (isMap(parent)) {
960
+ const row = +path[path.length - 2];
961
+ const keyToRow = getNthKey(parent, row);
962
+ switch (+lastKey === 0 ? "key" : "value") {
523
963
  case "key": {
524
- let e = n(a);
525
- r.set(e, r.get(a)), e !== a && r.delete(a);
964
+ const newKey = mapper(keyToRow);
965
+ parent.set(newKey, parent.get(keyToRow));
966
+ if (newKey !== keyToRow) parent.delete(keyToRow);
526
967
  break;
527
968
  }
528
- case "value": r.set(a, n(r.get(a)));
969
+ case "value": parent.set(keyToRow, mapper(parent.get(keyToRow)));
529
970
  }
530
971
  }
531
- return e;
532
- }, enableLegacyPaths = (e) => e < 1;
533
- function traverse(e, t, n, r = []) {
534
- if (!e) return;
535
- let i = enableLegacyPaths(n);
536
- if (!W(e)) {
537
- forEach(e, (e, a) => traverse(e, t, n, [...r, ...parsePath(a, i)]));
972
+ return object;
973
+ };
974
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/plainer.js
975
+ var enableLegacyPaths = (version) => version < 1;
976
+ function traverse(tree, walker, version, origin = []) {
977
+ if (!tree) return;
978
+ const legacyPaths = enableLegacyPaths(version);
979
+ if (!isArray$1(tree)) {
980
+ forEach(tree, (subtree, key) => traverse(subtree, walker, version, [...origin, ...parsePath(key, legacyPaths)]));
538
981
  return;
539
982
  }
540
- let [a, o] = e;
541
- o && forEach(o, (e, a) => {
542
- traverse(e, t, n, [...r, ...parsePath(a, i)]);
543
- }), t(a, r);
544
- }
545
- function applyValueAnnotations(e, t, n, r) {
546
- return traverse(t, (t, n) => {
547
- e = setDeep(e, n, (e) => untransformValue(e, t, r));
548
- }, n), e;
549
- }
550
- function applyReferentialEqualityAnnotations(e, t, n) {
551
- let r = enableLegacyPaths(n);
552
- function apply(t, n) {
553
- let i = getDeep(e, parsePath(n, r));
554
- t.map((e) => parsePath(e, r)).forEach((t) => {
555
- e = setDeep(e, t, () => i);
983
+ const [nodeValue, children] = tree;
984
+ if (children) forEach(children, (child, key) => {
985
+ traverse(child, walker, version, [...origin, ...parsePath(key, legacyPaths)]);
986
+ });
987
+ walker(nodeValue, origin);
988
+ }
989
+ function applyValueAnnotations(plain, annotations, version, superJson) {
990
+ traverse(annotations, (type, path) => {
991
+ plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
992
+ }, version);
993
+ return plain;
994
+ }
995
+ function applyReferentialEqualityAnnotations(plain, annotations, version) {
996
+ const legacyPaths = enableLegacyPaths(version);
997
+ function apply(identicalPaths, path) {
998
+ const object = getDeep(plain, parsePath(path, legacyPaths));
999
+ identicalPaths.map((path) => parsePath(path, legacyPaths)).forEach((identicalObjectPath) => {
1000
+ plain = setDeep(plain, identicalObjectPath, () => object);
1001
+ });
1002
+ }
1003
+ if (isArray$1(annotations)) {
1004
+ const [root, other] = annotations;
1005
+ root.forEach((identicalPath) => {
1006
+ plain = setDeep(plain, parsePath(identicalPath, legacyPaths), () => plain);
556
1007
  });
1008
+ if (other) forEach(other, apply);
1009
+ } else forEach(annotations, apply);
1010
+ return plain;
1011
+ }
1012
+ var isDeep = (object, superJson) => isPlainObject$1(object) || isArray$1(object) || isMap(object) || isSet(object) || isError(object) || isInstanceOfRegisteredClass(object, superJson);
1013
+ function addIdentity(object, path, identities) {
1014
+ const existingSet = identities.get(object);
1015
+ if (existingSet) existingSet.push(path);
1016
+ else identities.set(object, [path]);
1017
+ }
1018
+ function generateReferentialEqualityAnnotations(identitites, dedupe) {
1019
+ const result = {};
1020
+ let rootEqualityPaths = void 0;
1021
+ identitites.forEach((paths) => {
1022
+ if (paths.length <= 1) return;
1023
+ if (!dedupe) paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
1024
+ const [representativePath, ...identicalPaths] = paths;
1025
+ if (representativePath.length === 0) rootEqualityPaths = identicalPaths.map(stringifyPath);
1026
+ else result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
1027
+ });
1028
+ if (rootEqualityPaths) {
1029
+ if (isEmptyObject(result)) return [rootEqualityPaths];
1030
+ else return [rootEqualityPaths, result];
1031
+ } else return isEmptyObject(result) ? void 0 : result;
1032
+ }
1033
+ var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
1034
+ const primitive = isPrimitive(object);
1035
+ if (!primitive) {
1036
+ addIdentity(object, path, identities);
1037
+ const seen = seenObjects.get(object);
1038
+ if (seen) return dedupe ? { transformedValue: null } : seen;
1039
+ }
1040
+ if (!isDeep(object, superJson)) {
1041
+ const transformed = transformValue(object, superJson);
1042
+ const result = transformed ? {
1043
+ transformedValue: transformed.value,
1044
+ annotations: [transformed.type]
1045
+ } : { transformedValue: object };
1046
+ if (!primitive) seenObjects.set(object, result);
1047
+ return result;
557
1048
  }
558
- if (W(t)) {
559
- let [n, i] = t;
560
- n.forEach((t) => {
561
- e = setDeep(e, parsePath(t, r), () => e);
562
- }), i && forEach(i, apply);
563
- } else forEach(t, apply);
564
- return e;
565
- }
566
- var isDeep = (e, t) => U(e) || W(e) || isMap(e) || isSet(e) || isError(e) || isInstanceOfRegisteredClass(e, t);
567
- function addIdentity(e, t, n) {
568
- let r = n.get(e);
569
- r ? r.push(t) : n.set(e, [t]);
570
- }
571
- function generateReferentialEqualityAnnotations(e, t) {
572
- let n = {}, r;
573
- return e.forEach((e) => {
574
- if (e.length <= 1) return;
575
- t || (e = e.map((e) => e.map(String)).sort((e, t) => e.length - t.length));
576
- let [i, ...a] = e;
577
- i.length === 0 ? r = a.map(stringifyPath) : n[stringifyPath(i)] = a.map(stringifyPath);
578
- }), r ? isEmptyObject(n) ? [r] : [r, n] : isEmptyObject(n) ? void 0 : n;
579
- }
580
- var walker = (e, t, n, r, i = [], a = [], o = /* @__PURE__ */ new Map()) => {
581
- let s = isPrimitive(e);
582
- if (!s) {
583
- addIdentity(e, i, t);
584
- let n = o.get(e);
585
- if (n) return r ? { transformedValue: null } : n;
586
- }
587
- if (!isDeep(e, n)) {
588
- let t = transformValue(e, n), r = t ? {
589
- transformedValue: t.value,
590
- annotations: [t.type]
591
- } : { transformedValue: e };
592
- return s || o.set(e, r), r;
593
- }
594
- if (includes(a, e)) return { transformedValue: null };
595
- let c = transformValue(e, n), l = c?.value ?? e, u = W(l) ? [] : {}, d = {};
596
- forEach(l, (s, c) => {
597
- if (c === "__proto__" || c === "constructor" || c === "prototype") throw Error(`Detected property ${c}. This is a prototype pollution risk, please remove it from your object.`);
598
- let l = walker(s, t, n, r, [...i, c], [...a, e], o);
599
- u[c] = l.transformedValue, W(l.annotations) ? d[escapeKey(c)] = l.annotations : U(l.annotations) && forEach(l.annotations, (e, t) => {
600
- d[escapeKey(c) + "." + t] = e;
1049
+ if (includes(objectsInThisPath, object)) return { transformedValue: null };
1050
+ const transformationResult = transformValue(object, superJson);
1051
+ const transformed = transformationResult?.value ?? object;
1052
+ const transformedValue = isArray$1(transformed) ? [] : {};
1053
+ const innerAnnotations = {};
1054
+ forEach(transformed, (value, index) => {
1055
+ if (index === "__proto__" || index === "constructor" || index === "prototype") throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
1056
+ const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
1057
+ transformedValue[index] = recursiveResult.transformedValue;
1058
+ if (isArray$1(recursiveResult.annotations)) innerAnnotations[escapeKey(index)] = recursiveResult.annotations;
1059
+ else if (isPlainObject$1(recursiveResult.annotations)) forEach(recursiveResult.annotations, (tree, key) => {
1060
+ innerAnnotations[escapeKey(index) + "." + key] = tree;
601
1061
  });
602
1062
  });
603
- let f = isEmptyObject(d) ? {
604
- transformedValue: u,
605
- annotations: c ? [c.type] : void 0
1063
+ const result = isEmptyObject(innerAnnotations) ? {
1064
+ transformedValue,
1065
+ annotations: !!transformationResult ? [transformationResult.type] : void 0
606
1066
  } : {
607
- transformedValue: u,
608
- annotations: c ? [c.type, d] : d
1067
+ transformedValue,
1068
+ annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
609
1069
  };
610
- return s || o.set(e, f), f;
1070
+ if (!primitive) seenObjects.set(object, result);
1071
+ return result;
611
1072
  };
612
- //#endregion
613
- //#region ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/getType.js
614
- function getType(e) {
615
- return Object.prototype.toString.call(e).slice(8, -1);
616
- }
617
- //#endregion
618
- //#region ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isArray.js
619
- function isArray(e) {
620
- return getType(e) === "Array";
621
- }
622
- //#endregion
623
- //#region ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isPlainObject.js
624
- function isPlainObject(e) {
625
- if (getType(e) !== "Object") return !1;
626
- let t = Object.getPrototypeOf(e);
627
- return !!t && t.constructor === Object && t === Object.prototype;
628
- }
629
- //#endregion
630
- //#region ../../node_modules/.pnpm/copy-anything@4.0.5/node_modules/copy-anything/dist/index.js
631
- function assignProp(e, t, n, r, i) {
632
- let a = {}.propertyIsEnumerable.call(r, t) ? "enumerable" : "nonenumerable";
633
- a === "enumerable" && (e[t] = n), i && a === "nonenumerable" && Object.defineProperty(e, t, {
634
- value: n,
635
- enumerable: !1,
636
- writable: !0,
637
- configurable: !0
1073
+ // ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/getType.js
1074
+ /** Returns the object type of the given payload */
1075
+ function getType(payload) {
1076
+ return Object.prototype.toString.call(payload).slice(8, -1);
1077
+ }
1078
+ // ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isArray.js
1079
+ /** Returns whether the payload is an array */
1080
+ function isArray(payload) {
1081
+ return getType(payload) === "Array";
1082
+ }
1083
+ // ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isPlainObject.js
1084
+ /**
1085
+ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects
1086
+ * with other prototypes)
1087
+ */
1088
+ function isPlainObject(payload) {
1089
+ if (getType(payload) !== "Object") return false;
1090
+ const prototype = Object.getPrototypeOf(payload);
1091
+ return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
1092
+ }
1093
+ // ../../node_modules/.pnpm/copy-anything@4.0.5/node_modules/copy-anything/dist/index.js
1094
+ function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
1095
+ const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
1096
+ if (propType === "enumerable") carry[key] = newVal;
1097
+ if (includeNonenumerable && propType === "nonenumerable") Object.defineProperty(carry, key, {
1098
+ value: newVal,
1099
+ enumerable: false,
1100
+ writable: true,
1101
+ configurable: true
638
1102
  });
639
1103
  }
640
- function copy(e, t = {}) {
641
- if (isArray(e)) return e.map((e) => copy(e, t));
642
- if (!isPlainObject(e)) return e;
643
- let n = Object.getOwnPropertyNames(e), r = Object.getOwnPropertySymbols(e);
644
- return [...n, ...r].reduce((n, r) => {
645
- if (r === "__proto__" || isArray(t.props) && !t.props.includes(r)) return n;
646
- let i = e[r];
647
- return assignProp(n, r, copy(i, t), e, t.nonenumerable), n;
1104
+ /**
1105
+ * Copy (clone) an object and all its props recursively to get rid of any prop referenced of the
1106
+ * original object. Arrays are also cloned, however objects inside arrays are still linked.
1107
+ *
1108
+ * @param target Target can be anything
1109
+ * @param [options={}] See type {@link Options} for more details.
1110
+ *
1111
+ * - `{ props: ['key1'] }` will only copy the `key1` property. When using this you will need to cast
1112
+ * the return type manually (in order to keep the TS implementation in here simple I didn't
1113
+ * built a complex auto resolved type for those few cases people want to use this option)
1114
+ * - `{ nonenumerable: true }` will copy all non-enumerable properties. Default is `{}`
1115
+ *
1116
+ * @returns The target with replaced values
1117
+ */
1118
+ function copy(target, options = {}) {
1119
+ if (isArray(target)) return target.map((item) => copy(item, options));
1120
+ if (!isPlainObject(target)) return target;
1121
+ const props = Object.getOwnPropertyNames(target);
1122
+ const symbols = Object.getOwnPropertySymbols(target);
1123
+ return [...props, ...symbols].reduce((carry, key) => {
1124
+ if (key === "__proto__") return carry;
1125
+ if (isArray(options.props) && !options.props.includes(key)) return carry;
1126
+ const val = target[key];
1127
+ assignProp(carry, key, copy(val, options), target, options.nonenumerable);
1128
+ return carry;
648
1129
  }, {});
649
1130
  }
650
- //#endregion
651
- //#region ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/index.js
1131
+ // ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/index.js
652
1132
  var SuperJSON = class {
653
- constructor({ dedupe: e = !1 } = {}) {
654
- this.classRegistry = new ClassRegistry(), this.symbolRegistry = new Registry((e) => e.description ?? ""), this.customTransformerRegistry = new CustomTransformerRegistry(), this.allowedErrorProps = [], this.dedupe = e;
655
- }
656
- serialize(e) {
657
- let t = /* @__PURE__ */ new Map(), n = walker(e, t, this, this.dedupe), r = { json: n.transformedValue };
658
- n.annotations && (r.meta = {
659
- ...r.meta,
660
- values: n.annotations
661
- });
662
- let i = generateReferentialEqualityAnnotations(t, this.dedupe);
663
- return i && (r.meta = {
664
- ...r.meta,
665
- referentialEqualities: i
666
- }), r.meta && (r.meta.v = 1), r;
1133
+ /**
1134
+ * @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
1135
+ */
1136
+ constructor({ dedupe = false } = {}) {
1137
+ this.classRegistry = new ClassRegistry();
1138
+ this.symbolRegistry = new Registry((s) => s.description ?? "");
1139
+ this.customTransformerRegistry = new CustomTransformerRegistry();
1140
+ this.allowedErrorProps = [];
1141
+ this.dedupe = dedupe;
1142
+ }
1143
+ serialize(object) {
1144
+ const identities = /* @__PURE__ */ new Map();
1145
+ const output = walker(object, identities, this, this.dedupe);
1146
+ const res = { json: output.transformedValue };
1147
+ if (output.annotations) res.meta = {
1148
+ ...res.meta,
1149
+ values: output.annotations
1150
+ };
1151
+ const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
1152
+ if (equalityAnnotations) res.meta = {
1153
+ ...res.meta,
1154
+ referentialEqualities: equalityAnnotations
1155
+ };
1156
+ if (res.meta) res.meta.v = 1;
1157
+ return res;
667
1158
  }
668
- deserialize(e, t) {
669
- let { json: n, meta: r } = e, i = t?.inPlace ? n : copy(n);
670
- return r?.values && (i = applyValueAnnotations(i, r.values, r.v ?? 0, this)), r?.referentialEqualities && (i = applyReferentialEqualityAnnotations(i, r.referentialEqualities, r.v ?? 0)), i;
1159
+ deserialize(payload, options) {
1160
+ const { json, meta } = payload;
1161
+ let result = options?.inPlace ? json : copy(json);
1162
+ if (meta?.values) result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this);
1163
+ if (meta?.referentialEqualities) result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities, meta.v ?? 0);
1164
+ return result;
671
1165
  }
672
- stringify(e) {
673
- return JSON.stringify(this.serialize(e));
1166
+ stringify(object) {
1167
+ return JSON.stringify(this.serialize(object));
674
1168
  }
675
- parse(e) {
676
- return this.deserialize(JSON.parse(e), { inPlace: !0 });
1169
+ parse(string) {
1170
+ return this.deserialize(JSON.parse(string), { inPlace: true });
677
1171
  }
678
- registerClass(e, t) {
679
- this.classRegistry.register(e, t);
1172
+ registerClass(v, options) {
1173
+ this.classRegistry.register(v, options);
680
1174
  }
681
- registerSymbol(e, t) {
682
- this.symbolRegistry.register(e, t);
1175
+ registerSymbol(v, identifier) {
1176
+ this.symbolRegistry.register(v, identifier);
683
1177
  }
684
- registerCustom(e, t) {
1178
+ registerCustom(transformer, name) {
685
1179
  this.customTransformerRegistry.register({
686
- name: t,
687
- ...e
1180
+ name,
1181
+ ...transformer
688
1182
  });
689
1183
  }
690
- allowErrorProps(...e) {
691
- this.allowedErrorProps.push(...e);
1184
+ allowErrorProps(...props) {
1185
+ this.allowedErrorProps.push(...props);
692
1186
  }
693
1187
  };
694
- SuperJSON.defaultInstance = new SuperJSON(), SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance), SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance), SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance), SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance), SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance), SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance), SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance), SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance), SuperJSON.serialize, SuperJSON.deserialize;
695
- var ke = SuperJSON.stringify, Ae = SuperJSON.parse;
696
- SuperJSON.registerClass, SuperJSON.registerCustom, SuperJSON.registerSymbol, SuperJSON.allowErrorProps;
697
- //#endregion
698
- //#region src/aichat/useChat.tsx
699
- function mapToNodeData(e) {
700
- return ({ id: t, data: n, ...r }) => {
701
- let i = n.icon ?? void 0;
702
- i === "none" && (i = void 0);
703
- let a = e.parentLookup.get(t)?.values().map((e) => e.id).toArray();
1188
+ SuperJSON.defaultInstance = new SuperJSON();
1189
+ SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
1190
+ SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
1191
+ SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
1192
+ SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
1193
+ SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
1194
+ SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
1195
+ SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
1196
+ SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
1197
+ SuperJSON.serialize;
1198
+ SuperJSON.deserialize;
1199
+ var stringify = SuperJSON.stringify;
1200
+ var parse = SuperJSON.parse;
1201
+ SuperJSON.registerClass;
1202
+ SuperJSON.registerCustom;
1203
+ SuperJSON.registerSymbol;
1204
+ SuperJSON.allowErrorProps;
1205
+ // src/aichat/useChat.tsx
1206
+ function mapToNodeData(storeState) {
1207
+ return ({ id, data, ...node }) => {
1208
+ let icon = data.icon ?? void 0;
1209
+ if (icon === "none") icon = void 0;
1210
+ let children = storeState.parentLookup.get(id)?.values().map((child) => child.id).toArray();
704
1211
  return {
705
- id: t,
706
- title: n.title,
707
- shape: n.shape,
708
- color: n.color,
709
- icon: i,
710
- parentId: r.parentId,
711
- children: a,
712
- x: n.x,
713
- y: n.y,
714
- width: r.measured?.width ?? r.width ?? r.initialWidth ?? 0,
715
- height: r.measured?.height ?? r.height ?? r.initialHeight ?? 0,
716
- ..."modelFqn" in n && n.modelFqn && { modelFqn: n.modelFqn }
1212
+ id,
1213
+ title: data.title,
1214
+ shape: data.shape,
1215
+ color: data.color,
1216
+ icon,
1217
+ parentId: node.parentId,
1218
+ children,
1219
+ x: data.x,
1220
+ y: data.y,
1221
+ width: node.measured?.width ?? node.width ?? node.initialWidth ?? 0,
1222
+ height: node.measured?.height ?? node.height ?? node.initialHeight ?? 0,
1223
+ ..."modelFqn" in data && data.modelFqn && { modelFqn: data.modelFqn }
717
1224
  };
718
1225
  };
719
1226
  }
720
1227
  function useChatTools() {
721
- let e = F(11), { id: n } = f(), a = t(), o = d(), s;
722
- if (e[0] !== o || e[1] !== a || e[2] !== n) {
1228
+ const $ = c(11);
1229
+ const { id: projectId } = useCurrentProject();
1230
+ const navigate = useNavigate();
1231
+ const diagram = useDiagram();
1232
+ let t0;
1233
+ if ($[0] !== diagram || $[1] !== navigate || $[2] !== projectId) {
723
1234
  let t1;
724
- e[4] === a ? t1 = e[5] : (t1 = (e) => {
725
- let { viewId: t } = e;
726
- return a({
727
- to: "./",
728
- params: (e) => ({
729
- ...e,
730
- viewId: t
731
- })
732
- }), {};
733
- }, e[4] = a, e[5] = t1);
1235
+ if ($[4] !== navigate) {
1236
+ t1 = (t2) => {
1237
+ const { viewId } = t2;
1238
+ navigate({
1239
+ to: "./",
1240
+ params: (current) => ({
1241
+ ...current,
1242
+ viewId
1243
+ })
1244
+ });
1245
+ return {};
1246
+ };
1247
+ $[4] = navigate;
1248
+ $[5] = t1;
1249
+ } else t1 = $[5];
734
1250
  let t2;
735
- e[6] !== o || e[7] !== n ? (t2 = (e) => {
736
- let { view: t, focusedNode: a, xynodes: s, xystore: c, toggledFeatures: u, features: d } = o.getContext(), f = u.enableReadOnly ?? d.enableReadOnly, p = mapToNodeData(c.getState()), m = e.nodes === !0 && l(s, p) || void 0, h = e.selectedNode === !0 && r(s, i((e) => !!e.selected || e.id === a), (e) => e ? p(e) : void 0);
737
- return {
738
- projectId: n,
739
- editMode: !f,
740
- view: {
741
- id: t.id,
742
- title: t.title ?? "",
743
- type: t._type
744
- },
745
- ...m && { nodes: m },
746
- ...h && { selectedNode: h }
1251
+ if ($[6] !== diagram || $[7] !== projectId) {
1252
+ t2 = (params) => {
1253
+ const { view, focusedNode, xynodes, xystore, toggledFeatures, features } = diagram.getContext();
1254
+ const isReadOnly = toggledFeatures.enableReadOnly ?? features.enableReadOnly;
1255
+ const toNodeData = mapToNodeData(xystore.getState());
1256
+ const nodes = params.nodes === true && r(xynodes, toNodeData) || void 0;
1257
+ const selectedNode = params.selectedNode === true && f(xynodes, a$3((n) => !!n.selected || n.id === focusedNode), (n_0) => n_0 ? toNodeData(n_0) : void 0);
1258
+ return {
1259
+ projectId,
1260
+ editMode: !isReadOnly,
1261
+ view: {
1262
+ id: view.id,
1263
+ title: view.title ?? "",
1264
+ type: view._type
1265
+ },
1266
+ ...nodes && { nodes },
1267
+ ...selectedNode && { selectedNode }
1268
+ };
747
1269
  };
748
- }, e[6] = o, e[7] = n, e[8] = t2) : t2 = e[8];
1270
+ $[6] = diagram;
1271
+ $[7] = projectId;
1272
+ $[8] = t2;
1273
+ } else t2 = $[8];
749
1274
  let t3;
750
- e[9] === o ? t3 = e[10] : (t3 = (e) => {
751
- let { command: t } = e;
752
- bb50: switch (t.type) {
753
- case "focus":
754
- o.focusOnElement(t.elementId);
755
- break bb50;
756
- case "fitview":
757
- o.fitDiagram();
758
- break bb50;
759
- default: ve(t);
760
- }
761
- return {};
762
- }, e[9] = o, e[10] = t3), s = ue(Ee.client(t1), Se.client(t2), Te.client(t3)), e[0] = o, e[1] = a, e[2] = n, e[3] = s;
763
- } else s = e[3];
764
- return s;
1275
+ if ($[9] !== diagram) {
1276
+ t3 = (t4) => {
1277
+ const { command } = t4;
1278
+ bb50: switch (command.type) {
1279
+ case "focus":
1280
+ diagram.focusOnElement(command.elementId);
1281
+ break bb50;
1282
+ case "fitview":
1283
+ diagram.fitDiagram();
1284
+ break bb50;
1285
+ default: nonexhaustive(command);
1286
+ }
1287
+ return {};
1288
+ };
1289
+ $[9] = diagram;
1290
+ $[10] = t3;
1291
+ } else t3 = $[10];
1292
+ t0 = clientTools(navigateToDef.client(t1), readUiStateDef.client(t2), updateUiStateDef.client(t3));
1293
+ $[0] = diagram;
1294
+ $[1] = navigate;
1295
+ $[2] = projectId;
1296
+ $[3] = t0;
1297
+ } else t0 = $[3];
1298
+ return t0;
765
1299
  }
766
- var Q = {
1300
+ var storage$1 = {
767
1301
  key: "likec4.ai.chat.messages",
768
1302
  read() {
769
1303
  try {
770
- let e = sessionStorage.getItem(this.key);
771
- return e ? Ae(e) : [];
1304
+ const stored = sessionStorage.getItem(this.key);
1305
+ if (!stored) return [];
1306
+ return parse(stored);
772
1307
  } catch {
773
1308
  return [];
774
1309
  }
775
1310
  },
776
- write(e) {
1311
+ write(messages) {
777
1312
  try {
778
- if (e.length === 0) {
1313
+ if (messages.length === 0) {
779
1314
  sessionStorage.removeItem(this.key);
780
1315
  return;
781
1316
  }
782
- sessionStorage.setItem(this.key, ke(e));
1317
+ sessionStorage.setItem(this.key, stringify(messages));
783
1318
  } catch {}
784
1319
  }
785
1320
  };
786
- function useChat(e) {
787
- let t = F(7), n;
788
- t[0] === Symbol.for("react.memo_cache_sentinel") ? (n = {
789
- connection: ce("/__likec4_ai"),
790
- initialMessages: Q.read()
791
- }, t[0] = n) : n = t[0];
792
- let r = n, i = useChatTools(), a;
793
- t[1] !== e || t[2] !== i ? (a = {
794
- ...r,
795
- ...e,
796
- tools: i
797
- }, t[1] = e, t[2] = i, t[3] = a) : a = t[3];
798
- let o = le(a), t3, s;
799
- return t[4] === o.messages ? (t3 = t[5], s = t[6]) : (t3 = () => {
800
- Q.write(o.messages);
801
- }, s = [o.messages], t[4] = o.messages, t[5] = t3, t[6] = s), me(t3, s), o;
802
- }
803
- //#endregion
804
- //#region src/aichat/AIChat.tsx
805
- var $ = {
1321
+ function useChat(options) {
1322
+ const $ = c(9);
1323
+ let t0;
1324
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1325
+ t0 = {
1326
+ connection: fetchServerSentEvents("/__likec4_ai"),
1327
+ initialMessages: storage$1.read()
1328
+ };
1329
+ $[0] = t0;
1330
+ } else t0 = $[0];
1331
+ const memoProps = t0;
1332
+ let t1;
1333
+ if ($[1] !== options) {
1334
+ t1 = options ?? {};
1335
+ $[1] = options;
1336
+ $[2] = t1;
1337
+ } else t1 = $[2];
1338
+ const t2 = useChatTools();
1339
+ let t3;
1340
+ if ($[3] !== t1 || $[4] !== t2) {
1341
+ t3 = {
1342
+ ...memoProps,
1343
+ ...t1,
1344
+ tools: t2
1345
+ };
1346
+ $[3] = t1;
1347
+ $[4] = t2;
1348
+ $[5] = t3;
1349
+ } else t3 = $[5];
1350
+ const chat = useChat$1(t3);
1351
+ let t4;
1352
+ let t5;
1353
+ if ($[6] !== chat.messages) {
1354
+ t4 = () => {
1355
+ storage$1.write(chat.messages);
1356
+ };
1357
+ t5 = [chat.messages];
1358
+ $[6] = chat.messages;
1359
+ $[7] = t4;
1360
+ $[8] = t5;
1361
+ } else {
1362
+ t4 = $[7];
1363
+ t5 = $[8];
1364
+ }
1365
+ useEffect(t4, t5);
1366
+ return chat;
1367
+ }
1368
+ // src/aichat/AIChat.tsx
1369
+ var storage = {
806
1370
  key: "likec4.ai.chat.position",
807
1371
  read() {
808
1372
  try {
809
- let e = localStorage.getItem(this.key);
810
- return e ? JSON.parse(e) : null;
1373
+ const stored = localStorage.getItem(this.key);
1374
+ if (!stored) return null;
1375
+ return JSON.parse(stored);
811
1376
  } catch {
812
1377
  return null;
813
1378
  }
814
1379
  },
815
- write(e) {
1380
+ write(position) {
816
1381
  try {
817
- if (e === null) return localStorage.removeItem(this.key), e;
818
- localStorage.setItem(this.key, JSON.stringify(e));
1382
+ if (position === null) {
1383
+ localStorage.removeItem(this.key);
1384
+ return position;
1385
+ }
1386
+ localStorage.setItem(this.key, JSON.stringify(position));
819
1387
  } catch {}
820
- return e;
1388
+ return position;
821
1389
  }
822
1390
  };
823
1391
  function AIChatComponent() {
824
- let e = P(null);
825
- e.current ||= $.read() ?? {
1392
+ const initialPosition = useRef(null);
1393
+ if (!initialPosition.current) initialPosition.current = storage.read() ?? {
826
1394
  right: 16,
827
1395
  bottom: 100
828
1396
  };
829
- let onPositionChange = (t) => {
830
- e.current = $.write({
831
- left: t.x,
832
- top: t.y
1397
+ const onPositionChange = (pos) => {
1398
+ initialPosition.current = storage.write({
1399
+ left: pos.x,
1400
+ top: pos.y
833
1401
  });
834
- }, [t, n] = ne({
1402
+ };
1403
+ const [isCollapsed, setCollapsed] = useLocalStorage({
835
1404
  key: "likec4.ai.chat.collapsed",
836
- defaultValue: !0
1405
+ defaultValue: true
837
1406
  });
838
- return /* @__PURE__ */ R(I, { children: [/* @__PURE__ */ R(oe, { children: [!t && /* @__PURE__ */ L(v, {
1407
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(AnimatePresence, { children: [!isCollapsed && /* @__PURE__ */ jsx(FloatingWindow, {
839
1408
  w: 300,
840
1409
  pos: "fixed",
841
- className: C({
1410
+ className: css({
842
1411
  rounded: "md",
843
1412
  padding: "xs",
844
1413
  shadow: "md",
845
1414
  layerStyle: "likec4.panel"
846
1415
  }),
847
- constrainToViewport: !0,
1416
+ constrainToViewport: true,
848
1417
  constrainOffset: 8,
849
1418
  excludeDragHandleSelector: ".chat-input",
850
- initialPosition: e.current,
1419
+ initialPosition: initialPosition.current,
851
1420
  onPositionChange,
852
- children: /* @__PURE__ */ L(AIChatWindowContent, { onClose: () => n(!0) })
853
- }), t && /* @__PURE__ */ L(ae.div, {
1421
+ children: /* @__PURE__ */ jsx(AIChatWindowContent, { onClose: () => setCollapsed(true) })
1422
+ }), isCollapsed && /* @__PURE__ */ jsx(m.div, {
854
1423
  initial: {
855
1424
  opacity: .1,
856
1425
  translateX: "10%"
@@ -869,83 +1438,130 @@ function AIChatComponent() {
869
1438
  bottom: 60,
870
1439
  zIndex: 1e3
871
1440
  },
872
- children: /* @__PURE__ */ L(ie, {
1441
+ children: /* @__PURE__ */ jsx(Tooltip, {
873
1442
  label: "Show AI Assistant",
874
1443
  color: "dark",
875
1444
  fz: "xs",
876
- children: /* @__PURE__ */ L(x, {
1445
+ children: /* @__PURE__ */ jsx(ActionIcon, {
877
1446
  size: "lg",
878
1447
  variant: "gradient",
879
- onClick: () => n(!1),
880
- children: /* @__PURE__ */ L(u, { stroke: 1.5 })
1448
+ onClick: () => setCollapsed(false),
1449
+ children: /* @__PURE__ */ jsx(IconSparkles, { stroke: 1.5 })
881
1450
  })
882
1451
  })
883
- }, "collapsed")] }), /* @__PURE__ */ L(SemanticLayoutLog, {})] });
884
- }
885
- function AIChatWindowContent(e) {
886
- let t = F(15), { onClose: r } = e, i = P(null), t1;
887
- t[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
888
- i.current?.scrollIntoView();
889
- }, t[0] = t1) : t1 = t[0];
890
- let a = t1, t2;
891
- t[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => {
892
- a();
893
- }, t[1] = t2) : t2 = t[1], n(t2, 100);
894
- let o;
895
- t[2] === Symbol.for("react.memo_cache_sentinel") ? (o = { onChunk: a }, t[2] = o) : o = t[2];
896
- let s = useChat(o), c;
897
- t[3] === Symbol.for("react.memo_cache_sentinel") ? (c = /* @__PURE__ */ R(S, { children: [/* @__PURE__ */ L(T, {
898
- textStyle: "likec4.panel",
899
- nouserselect: !0,
900
- children: "AI Assistant"
901
- }), /* @__PURE__ */ L(b, {
902
- size: "xs",
903
- radius: "sm",
904
- variant: "light",
905
- children: be
906
- })] }), t[3] = c) : c = t[3];
907
- let l;
908
- t[4] === r ? l = t[5] : (l = /* @__PURE__ */ R(S, {
909
- cursor: "move",
910
- justify: "space-between",
911
- children: [c, /* @__PURE__ */ L(te, {
912
- size: "sm",
913
- onClick: (e) => {
914
- e.stopPropagation(), r();
915
- }
916
- })]
917
- }), t[4] = r, t[5] = l);
918
- let u;
919
- t[6] === Symbol.for("react.memo_cache_sentinel") ? (u = { content: C({ display: "contents" }) }, t[6] = u) : u = t[6];
920
- let d;
921
- t[7] === Symbol.for("react.memo_cache_sentinel") ? (d = /* @__PURE__ */ L(ChatMessages, {}), t[7] = d) : d = t[7];
922
- let f, p;
923
- t[8] === Symbol.for("react.memo_cache_sentinel") ? (f = /* @__PURE__ */ L(h, {
924
- scrollbars: "y",
925
- w: "100%",
926
- flex: 1,
927
- mih: 250,
928
- mah: 350,
929
- classNames: u,
930
- children: /* @__PURE__ */ R(w, { children: [d, /* @__PURE__ */ L("div", {
931
- ref: i,
932
- style: { height: 2 }
933
- })] })
934
- }), p = /* @__PURE__ */ L(ChatInput, {}), t[8] = f, t[9] = p) : (f = t[8], p = t[9]);
935
- let m;
936
- t[10] === l ? m = t[11] : (m = /* @__PURE__ */ R(w, {
937
- w: "100%",
938
- children: [
939
- l,
940
- f,
941
- p
942
- ]
943
- }), t[10] = l, t[11] = m);
944
- let g;
945
- return t[12] !== s || t[13] !== m ? (g = /* @__PURE__ */ L(z, {
946
- value: s,
947
- children: m
948
- }), t[12] = s, t[13] = m, t[14] = g) : g = t[14], g;
949
- }
950
- //#endregion
1452
+ }, "collapsed")] }), /* @__PURE__ */ jsx(SemanticLayoutLog, {})] });
1453
+ }
1454
+ function AIChatWindowContent(t0) {
1455
+ const $ = c(15);
1456
+ const { onClose } = t0;
1457
+ const scrollAnchorRef = useRef(null);
1458
+ let t1;
1459
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1460
+ t1 = () => {
1461
+ scrollAnchorRef.current?.scrollIntoView();
1462
+ };
1463
+ $[0] = t1;
1464
+ } else t1 = $[0];
1465
+ const scrollIntoView = t1;
1466
+ let t2;
1467
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
1468
+ t2 = () => {
1469
+ scrollIntoView();
1470
+ };
1471
+ $[1] = t2;
1472
+ } else t2 = $[1];
1473
+ useTimeoutEffect(t2, 100);
1474
+ let t3;
1475
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
1476
+ t3 = { onChunk: scrollIntoView };
1477
+ $[2] = t3;
1478
+ } else t3 = $[2];
1479
+ const chat = useChat(t3);
1480
+ let t4;
1481
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
1482
+ t4 = /* @__PURE__ */ jsxs(HStack, { children: [/* @__PURE__ */ jsx(Txt, {
1483
+ textStyle: "likec4.panel",
1484
+ nouserselect: true,
1485
+ children: "AI Assistant"
1486
+ }), /* @__PURE__ */ jsx(Badge, {
1487
+ size: "xs",
1488
+ radius: "sm",
1489
+ variant: "light",
1490
+ children: AIAdapter
1491
+ })] });
1492
+ $[3] = t4;
1493
+ } else t4 = $[3];
1494
+ let t5;
1495
+ if ($[4] !== onClose) {
1496
+ t5 = /* @__PURE__ */ jsxs(HStack, {
1497
+ cursor: "move",
1498
+ justify: "space-between",
1499
+ children: [t4, /* @__PURE__ */ jsx(CloseButton, {
1500
+ size: "sm",
1501
+ onClick: (e) => {
1502
+ e.stopPropagation();
1503
+ onClose();
1504
+ }
1505
+ })]
1506
+ });
1507
+ $[4] = onClose;
1508
+ $[5] = t5;
1509
+ } else t5 = $[5];
1510
+ let t6;
1511
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
1512
+ t6 = { content: css({ display: "contents" }) };
1513
+ $[6] = t6;
1514
+ } else t6 = $[6];
1515
+ let t7;
1516
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
1517
+ t7 = /* @__PURE__ */ jsx(ChatMessages, {});
1518
+ $[7] = t7;
1519
+ } else t7 = $[7];
1520
+ let t8;
1521
+ let t9;
1522
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
1523
+ t8 = /* @__PURE__ */ jsx(ScrollAreaAutosize, {
1524
+ scrollbars: "y",
1525
+ w: "100%",
1526
+ flex: 1,
1527
+ mih: 250,
1528
+ mah: 350,
1529
+ classNames: t6,
1530
+ children: /* @__PURE__ */ jsxs(VStack, { children: [t7, /* @__PURE__ */ jsx("div", {
1531
+ ref: scrollAnchorRef,
1532
+ style: { height: 2 }
1533
+ })] })
1534
+ });
1535
+ t9 = /* @__PURE__ */ jsx(ChatInput, {});
1536
+ $[8] = t8;
1537
+ $[9] = t9;
1538
+ } else {
1539
+ t8 = $[8];
1540
+ t9 = $[9];
1541
+ }
1542
+ let t10;
1543
+ if ($[10] !== t5) {
1544
+ t10 = /* @__PURE__ */ jsxs(VStack, {
1545
+ w: "100%",
1546
+ children: [
1547
+ t5,
1548
+ t8,
1549
+ t9
1550
+ ]
1551
+ });
1552
+ $[10] = t5;
1553
+ $[11] = t10;
1554
+ } else t10 = $[11];
1555
+ let t11;
1556
+ if ($[12] !== chat || $[13] !== t10) {
1557
+ t11 = /* @__PURE__ */ jsx(ChatContext, {
1558
+ value: chat,
1559
+ children: t10
1560
+ });
1561
+ $[12] = chat;
1562
+ $[13] = t10;
1563
+ $[14] = t11;
1564
+ } else t11 = $[14];
1565
+ return t11;
1566
+ }
951
1567
  export { AIChatComponent as default };