likec4 1.57.0 → 1.58.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.
- package/__app__/codegen/react.mjs +7 -8
- package/__app__/codegen/webcomponent.mjs +70 -881
- package/__app__/src/aichat/index.mjs +8 -1
- package/__app__/src/chunks/AIChat.mjs +959 -0
- package/__app__/src/chunks/DiagramActorProvider.mjs +7638 -0
- package/__app__/src/chunks/LikeC4Styles.mjs +1866 -0
- package/__app__/src/chunks/Markdown.mjs +146 -0
- package/__app__/src/chunks/NavigationPanel.mjs +61 -0
- package/__app__/src/chunks/ProjectsOverview.mjs +540 -0
- package/__app__/src/chunks/adhoc-editor.mjs +3386 -0
- package/__app__/src/chunks/es.mjs +439 -0
- package/__app__/src/chunks/hooks.mjs +145 -0
- package/__app__/src/chunks/libs/@dagrejs/dagre.mjs +1894 -0
- package/__app__/src/chunks/libs/@floating-ui.mjs +2218 -0
- package/__app__/src/chunks/libs/@mantine.mjs +12070 -0
- package/__app__/src/chunks/libs/@tabler/icons-react.mjs +252 -0
- package/__app__/src/chunks/libs/@tanstack-ai.mjs +1768 -0
- package/__app__/src/chunks/libs/@tanstack.mjs +2718 -0
- package/__app__/src/chunks/libs/@xstate/react.mjs +1982 -0
- package/__app__/src/chunks/libs/@xyflow/react.mjs +5256 -0
- package/__app__/src/chunks/libs/bezier-js.mjs +1003 -0
- package/__app__/src/chunks/libs/d3.mjs +2842 -0
- package/__app__/src/chunks/libs/fast-equals.mjs +268 -0
- package/__app__/src/chunks/libs/framer.mjs +5872 -0
- package/__app__/src/chunks/libs/remeda.mjs +642 -0
- package/__app__/src/chunks/libs/zod.mjs +3170 -0
- package/__app__/src/chunks/rolldown-runtime.mjs +23 -0
- package/__app__/src/chunks/styled-system.mjs +1040 -0
- package/__app__/src/fonts.css +1 -1
- package/__app__/src/main.mjs +14816 -14
- package/__app__/src/style.css +1 -1
- package/dist/chunks/enableServer.mjs +1 -1
- package/dist/chunks/filenames.mjs +2 -2
- package/dist/chunks/index2.d.mts +1877 -734
- package/dist/chunks/libs/@chevrotain/gast.mjs +1 -1
- package/dist/chunks/libs/@logtape/logtape.mjs +4 -3
- package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
- package/dist/chunks/libs/chevrotain.mjs +25 -25
- package/dist/chunks/libs/langium.mjs +1 -1
- package/dist/chunks/libs/merge-error-cause.mjs +1 -1
- package/dist/chunks/libs/pretty-ms.mjs +1 -1
- package/dist/chunks/libs/remeda.mjs +1 -1
- package/dist/chunks/libs/ufo.mjs +1 -1
- package/dist/chunks/libs/unstorage.mjs +1 -1
- package/dist/chunks/libs/which.mjs +1 -1
- package/dist/chunks/libs/zod.mjs +65 -0
- package/dist/chunks/node.mjs +73 -62
- package/dist/chunks/{plugin.mjs → vite-plugin.mjs} +41 -41
- package/dist/cli/index.mjs +184 -144
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/model/index.d.mts +1 -1
- package/dist/vite-plugin/index.mjs +1 -1
- package/dist/vite-plugin/internal/index.d.mts +52 -57
- package/dist/vite-plugin/internal/index.mjs +946 -1
- package/package.json +46 -47
- package/react/index.d.mts +92 -23
- package/react/index.mjs +44551 -42605
- package/__app__/chunks/AIChat2.mjs +0 -2
- package/__app__/chunks/DiagramActorProvider.mjs +0 -10
- package/__app__/chunks/EmbedPage.mjs +0 -1
- package/__app__/chunks/ExportPage.mjs +0 -2
- package/__app__/chunks/LikeC4Diagram.mjs +0 -19
- package/__app__/chunks/LikeC4Styles.mjs +0 -48
- package/__app__/chunks/Markdown.mjs +0 -1
- package/__app__/chunks/NavigationPanel.mjs +0 -1
- package/__app__/chunks/ViewReact.mjs +0 -1
- package/__app__/chunks/adhoc-editor.mjs +0 -1
- package/__app__/chunks/aichat.mjs +0 -1
- package/__app__/chunks/box.mjs +0 -1
- package/__app__/chunks/create-style-context.mjs +0 -1
- package/__app__/chunks/css.mjs +0 -1
- package/__app__/chunks/factory.mjs +0 -1
- package/__app__/chunks/hooks.mjs +0 -1
- package/__app__/chunks/hstack.mjs +0 -1
- package/__app__/chunks/libs/@dagrejs/dagre.mjs +0 -1
- package/__app__/chunks/libs/@floating-ui/core.mjs +0 -1
- package/__app__/chunks/libs/@floating-ui/dom.mjs +0 -1
- package/__app__/chunks/libs/@floating-ui/react.mjs +0 -1
- package/__app__/chunks/libs/@mantine/core.mjs +0 -41
- package/__app__/chunks/libs/@mantine/hooks.mjs +0 -1
- package/__app__/chunks/libs/@nanostores/react.mjs +0 -1
- package/__app__/chunks/libs/@react-hookz/web.mjs +0 -1
- package/__app__/chunks/libs/@tabler/icons-react.mjs +0 -358
- package/__app__/chunks/libs/@tanstack/ai-client.mjs +0 -2
- package/__app__/chunks/libs/@tanstack/ai-react-ui.mjs +0 -1
- package/__app__/chunks/libs/@tanstack/ai-react.mjs +0 -1
- package/__app__/chunks/libs/@tanstack/ai.mjs +0 -2
- package/__app__/chunks/libs/@tanstack/history.mjs +0 -1
- package/__app__/chunks/libs/@tanstack/react-router.mjs +0 -3
- package/__app__/chunks/libs/@tanstack/router-core.mjs +0 -1
- package/__app__/chunks/libs/@xstate/react.mjs +0 -1
- package/__app__/chunks/libs/@xstate/store.mjs +0 -1
- package/__app__/chunks/libs/@xyflow/react.mjs +0 -7
- package/__app__/chunks/libs/@zag-js/anatomy.mjs +0 -1
- package/__app__/chunks/libs/@zag-js/collection.mjs +0 -1
- package/__app__/chunks/libs/@zag-js/core.mjs +0 -1
- package/__app__/chunks/libs/@zag-js/react.mjs +0 -1
- package/__app__/chunks/libs/@zag-js/tree-view.mjs +0 -1
- package/__app__/chunks/libs/bezier-js.mjs +0 -1
- package/__app__/chunks/libs/copy-anything.mjs +0 -1
- package/__app__/chunks/libs/d3-path.mjs +0 -1
- package/__app__/chunks/libs/d3-shape.mjs +0 -1
- package/__app__/chunks/libs/fast-equals.mjs +0 -1
- package/__app__/chunks/libs/framer-motion.mjs +0 -9
- package/__app__/chunks/libs/html-to-image.mjs +0 -2
- package/__app__/chunks/libs/motion-dom.mjs +0 -1
- package/__app__/chunks/libs/nanostores.mjs +0 -1
- package/__app__/chunks/libs/react-error-boundary.mjs +0 -1
- package/__app__/chunks/libs/react-resizable-panels.mjs +0 -1
- package/__app__/chunks/libs/remeda.mjs +0 -1
- package/__app__/chunks/libs/superjson.mjs +0 -1
- package/__app__/chunks/libs/zod.mjs +0 -64
- package/__app__/chunks/rolldown-runtime.mjs +0 -1
- package/__app__/chunks/styles.css.mjs +0 -1
- package/__app__/chunks/txt.mjs +0 -1
- package/__app__/chunks/useLikeC4Project.mjs +0 -1
- package/__app__/src/pages/AdHocViewEditor.mjs +0 -1
- package/__app__/src/pages/EmbedPage.mjs +0 -1
- package/__app__/src/pages/ExportPage.mjs +0 -1
- package/__app__/src/pages/ProjectsOverview.mjs +0 -1
- package/__app__/src/pages/ViewAsD2.mjs +0 -1
- package/__app__/src/pages/ViewAsDot.mjs +0 -1
- package/__app__/src/pages/ViewAsMmd.mjs +0 -1
- package/__app__/src/pages/ViewAsPuml.mjs +0 -1
- package/__app__/src/pages/ViewEditor.mjs +0 -1
- package/__app__/src/pages/ViewReact.mjs +0 -1
- package/dist/chunks/libs/@chevrotain/utils.mjs +0 -1
- package/dist/chunks/libs/@hono/mcp.mjs +0 -70
- package/dist/chunks/libs/@hono/node-server.mjs +0 -1
- package/dist/chunks/libs/@logtape/logtape.d.mts +0 -1023
- package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +0 -12
- package/dist/chunks/libs/ajv.mjs +0 -1
- package/dist/chunks/libs/ansi-align.mjs +0 -2
- package/dist/chunks/libs/ansi-regex.mjs +0 -1
- package/dist/chunks/libs/ansi-styles.mjs +0 -1
- package/dist/chunks/libs/atomically.mjs +0 -1
- package/dist/chunks/libs/boxen.mjs +0 -22
- package/dist/chunks/libs/conf.mjs +0 -1
- package/dist/chunks/libs/defu.mjs +0 -1
- package/dist/chunks/libs/destr.mjs +0 -1
- package/dist/chunks/libs/find-up-simple.mjs +0 -1
- package/dist/chunks/libs/get-port.mjs +0 -1
- package/dist/chunks/libs/hono.mjs +0 -1
- package/dist/chunks/libs/is-docker.mjs +0 -1
- package/dist/chunks/libs/is-error-instance.mjs +0 -1
- package/dist/chunks/libs/is-inside-container.mjs +0 -1
- package/dist/chunks/libs/is-plain-obj.mjs +0 -1
- package/dist/chunks/libs/isexe.mjs +0 -1
- package/dist/chunks/libs/ky.mjs +0 -3
- package/dist/chunks/libs/p-debounce.mjs +0 -1
- package/dist/chunks/libs/p-limit.mjs +0 -1
- package/dist/chunks/libs/p-timeout.mjs +0 -1
- package/dist/chunks/libs/package-up.mjs +0 -1
- package/dist/chunks/libs/parse-ms.mjs +0 -1
- package/dist/chunks/libs/safe-stringify.mjs +0 -1
- package/dist/chunks/libs/strip-indent.mjs +0 -1
- package/dist/chunks/libs/tinyrainbow.mjs +0 -1
- package/dist/chunks/libs/ts-graphviz.mjs +0 -1
- package/dist/chunks/libs/unctx.mjs +0 -1
- package/dist/chunks/libs/vscode-languageserver.mjs +0 -1
- package/dist/chunks/libs/word-wrap.mjs +0 -12
- package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.mjs +0 -1
- package/dist/vite-plugin/internal/chunks/libs/birpc.mjs +0 -1
- package/dist/vite-plugin/internal/chunks/libs/fast-equals.mjs +0 -1
- package/dist/vite-plugin/internal/chunks/libs/nanostores.mjs +0 -1
- package/dist/vite-plugin/internal/chunks/libs/remeda.mjs +0 -1
- package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +0 -1
|
@@ -1 +1,946 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LikeC4Model } from "@likec4/core/model";
|
|
2
|
+
import { useCallback, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/nanostores@1.3.0/node_modules/nanostores/atom/index.js
|
|
5
|
+
let listenerQueue = [];
|
|
6
|
+
let lqIndex = 0;
|
|
7
|
+
const QUEUE_ITEMS_PER_LISTENER = 4;
|
|
8
|
+
const nanostoresGlobal = globalThis.nanostoresGlobal ||= { epoch: 0 };
|
|
9
|
+
const atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
|
|
10
|
+
let listeners = [];
|
|
11
|
+
let $atom = {
|
|
12
|
+
get() {
|
|
13
|
+
if (!$atom.lc) $atom.listen(() => {})();
|
|
14
|
+
return $atom.value;
|
|
15
|
+
},
|
|
16
|
+
init: initialValue,
|
|
17
|
+
lc: 0,
|
|
18
|
+
listen(listener) {
|
|
19
|
+
$atom.lc = listeners.push(listener);
|
|
20
|
+
return () => {
|
|
21
|
+
for (let i = lqIndex + QUEUE_ITEMS_PER_LISTENER; i < listenerQueue.length;) if (listenerQueue[i] === listener) listenerQueue.splice(i, QUEUE_ITEMS_PER_LISTENER);
|
|
22
|
+
else i += QUEUE_ITEMS_PER_LISTENER;
|
|
23
|
+
let index = listeners.indexOf(listener);
|
|
24
|
+
if (~index) {
|
|
25
|
+
listeners.splice(index, 1);
|
|
26
|
+
if (!--$atom.lc) $atom.off();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
notify(oldValue, changedKey) {
|
|
31
|
+
nanostoresGlobal.epoch++;
|
|
32
|
+
let runListenerQueue = !listenerQueue.length;
|
|
33
|
+
for (let listener of listeners) listenerQueue.push(listener, $atom.value, oldValue, changedKey);
|
|
34
|
+
if (runListenerQueue) {
|
|
35
|
+
for (lqIndex = 0; lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) listenerQueue[lqIndex](listenerQueue[lqIndex + 1], listenerQueue[lqIndex + 2], listenerQueue[lqIndex + 3]);
|
|
36
|
+
listenerQueue.length = 0;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
off() {},
|
|
40
|
+
set(newValue) {
|
|
41
|
+
let oldValue = $atom.value;
|
|
42
|
+
if (oldValue !== newValue) {
|
|
43
|
+
$atom.value = newValue;
|
|
44
|
+
$atom.notify(oldValue);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
subscribe(listener) {
|
|
48
|
+
let unbind = $atom.listen(listener);
|
|
49
|
+
listener($atom.value);
|
|
50
|
+
return unbind;
|
|
51
|
+
},
|
|
52
|
+
value: initialValue
|
|
53
|
+
};
|
|
54
|
+
return $atom;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region ../../node_modules/.pnpm/nanostores@1.3.0/node_modules/nanostores/lifecycle/index.js
|
|
59
|
+
const MOUNT = 5;
|
|
60
|
+
const UNMOUNT = 6;
|
|
61
|
+
const REVERT_MUTATION = 10;
|
|
62
|
+
let on = (object, listener, eventKey, mutateStore) => {
|
|
63
|
+
object.events = object.events || {};
|
|
64
|
+
if (!object.events[eventKey + REVERT_MUTATION]) object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
|
|
65
|
+
object.events[eventKey].reduceRight((event, l) => (l(event), event), {
|
|
66
|
+
shared: {},
|
|
67
|
+
...eventProps
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
object.events[eventKey] = object.events[eventKey] || [];
|
|
71
|
+
object.events[eventKey].push(listener);
|
|
72
|
+
return () => {
|
|
73
|
+
let currentListeners = object.events[eventKey];
|
|
74
|
+
let index = currentListeners.indexOf(listener);
|
|
75
|
+
currentListeners.splice(index, 1);
|
|
76
|
+
if (!currentListeners.length) {
|
|
77
|
+
delete object.events[eventKey];
|
|
78
|
+
object.events[eventKey + REVERT_MUTATION]();
|
|
79
|
+
delete object.events[eventKey + REVERT_MUTATION];
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const STORE_UNMOUNT_DELAY = 1e3;
|
|
84
|
+
let onMount = ($store, initialize) => {
|
|
85
|
+
let listener = (payload) => {
|
|
86
|
+
let destroy = initialize(payload);
|
|
87
|
+
if (destroy) $store.events[UNMOUNT].push(destroy);
|
|
88
|
+
};
|
|
89
|
+
return on($store, listener, MOUNT, (runListeners) => {
|
|
90
|
+
let originListen = $store.listen;
|
|
91
|
+
$store.listen = (...args) => {
|
|
92
|
+
if (!$store.lc && !$store.active) {
|
|
93
|
+
$store.active = true;
|
|
94
|
+
runListeners();
|
|
95
|
+
}
|
|
96
|
+
return originListen(...args);
|
|
97
|
+
};
|
|
98
|
+
let originOff = $store.off;
|
|
99
|
+
$store.events[UNMOUNT] = [];
|
|
100
|
+
$store.off = () => {
|
|
101
|
+
originOff();
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
if ($store.active && !$store.lc) {
|
|
104
|
+
$store.active = false;
|
|
105
|
+
for (let destroy of $store.events[UNMOUNT]) destroy();
|
|
106
|
+
$store.events[UNMOUNT] = [];
|
|
107
|
+
}
|
|
108
|
+
}, STORE_UNMOUNT_DELAY);
|
|
109
|
+
};
|
|
110
|
+
return () => {
|
|
111
|
+
$store.listen = originListen;
|
|
112
|
+
$store.off = originOff;
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region ../../node_modules/.pnpm/nanostores@1.3.0/node_modules/nanostores/computed/index.js
|
|
119
|
+
let computedStore = (stores, cb, batched) => {
|
|
120
|
+
if (!Array.isArray(stores)) stores = [stores];
|
|
121
|
+
let previousArgs;
|
|
122
|
+
let currentEpoch;
|
|
123
|
+
let set = () => {
|
|
124
|
+
if (currentEpoch === nanostoresGlobal.epoch) return;
|
|
125
|
+
currentEpoch = nanostoresGlobal.epoch;
|
|
126
|
+
let args = stores.map(($store) => $store.get());
|
|
127
|
+
if (!previousArgs || args.some((arg, i) => arg !== previousArgs[i])) {
|
|
128
|
+
previousArgs = args;
|
|
129
|
+
let value = cb(...args);
|
|
130
|
+
if (value && value.then && value.t) value.then((asyncValue) => {
|
|
131
|
+
if (previousArgs === args) $computed.set(asyncValue);
|
|
132
|
+
});
|
|
133
|
+
else {
|
|
134
|
+
$computed.set(value);
|
|
135
|
+
currentEpoch = nanostoresGlobal.epoch;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
let $computed = /* @__PURE__ */ atom(void 0);
|
|
140
|
+
let get = $computed.get;
|
|
141
|
+
$computed.get = () => {
|
|
142
|
+
set();
|
|
143
|
+
return get();
|
|
144
|
+
};
|
|
145
|
+
let timer;
|
|
146
|
+
let run = batched ? () => {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
timer = setTimeout(set);
|
|
149
|
+
} : set;
|
|
150
|
+
onMount($computed, () => {
|
|
151
|
+
let unbinds = stores.map(($store) => $store.listen(run));
|
|
152
|
+
set();
|
|
153
|
+
return () => {
|
|
154
|
+
for (let unbind of unbinds) unbind();
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
return $computed;
|
|
158
|
+
};
|
|
159
|
+
const computed = /* @__NO_SIDE_EFFECTS__ */ (stores, fn) => computedStore(stores, fn);
|
|
160
|
+
const batched = /* @__NO_SIDE_EFFECTS__ */ (stores, fn) => computedStore(stores, fn, true);
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region ../../node_modules/.pnpm/nanostores@1.3.0/node_modules/nanostores/listen-keys/index.js
|
|
164
|
+
function listenKeys($store, keys, listener) {
|
|
165
|
+
let keysSet = new Set(keys).add(void 0);
|
|
166
|
+
return $store.listen((value, oldValue, changed) => {
|
|
167
|
+
if (keysSet.has(changed)) listener(value, oldValue, changed);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region ../../node_modules/.pnpm/nanostores@1.3.0/node_modules/nanostores/map/index.js
|
|
173
|
+
const map = /* @__NO_SIDE_EFFECTS__ */ (initial = {}) => {
|
|
174
|
+
let $map = /* @__PURE__ */ atom(initial);
|
|
175
|
+
$map.setKey = function(key, value) {
|
|
176
|
+
let oldMap = $map.value;
|
|
177
|
+
if (typeof value === "undefined" && key in $map.value) {
|
|
178
|
+
$map.value = { ...$map.value };
|
|
179
|
+
delete $map.value[key];
|
|
180
|
+
$map.notify(oldMap, key);
|
|
181
|
+
} else if ($map.value[key] !== value) {
|
|
182
|
+
$map.value = {
|
|
183
|
+
...$map.value,
|
|
184
|
+
[key]: value
|
|
185
|
+
};
|
|
186
|
+
$map.notify(oldMap, key);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
return $map;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region ../../node_modules/.pnpm/@nanostores+react@1.1.0_nanostores@1.3.0_react@19.2.7/node_modules/@nanostores/react/index.js
|
|
194
|
+
let emit = (snapshotRef, onChange) => (value) => {
|
|
195
|
+
if (snapshotRef.current === value) return;
|
|
196
|
+
snapshotRef.current = value;
|
|
197
|
+
onChange();
|
|
198
|
+
};
|
|
199
|
+
function useStore(store, { keys, deps = [store, keys], ssr } = {}) {
|
|
200
|
+
let snapshotRef = useRef();
|
|
201
|
+
snapshotRef.current = store.get();
|
|
202
|
+
let subscribe = useCallback((onChange) => {
|
|
203
|
+
emit(snapshotRef, onChange)(store.value);
|
|
204
|
+
return keys?.length > 0 ? listenKeys(store, keys, emit(snapshotRef, onChange)) : store.listen(emit(snapshotRef, onChange));
|
|
205
|
+
}, deps);
|
|
206
|
+
let get = () => snapshotRef.current;
|
|
207
|
+
let server = get;
|
|
208
|
+
if (ssr && "init" in store) server = ssr === "initial" ? () => store.init : ssr;
|
|
209
|
+
return useSyncExternalStore(subscribe, get, server);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region ../../node_modules/.pnpm/birpc@4.0.0/node_modules/birpc/dist/index.mjs
|
|
214
|
+
const TYPE_REQUEST = "q";
|
|
215
|
+
const TYPE_RESPONSE = "s";
|
|
216
|
+
function createPromiseWithResolvers() {
|
|
217
|
+
let resolve;
|
|
218
|
+
let reject;
|
|
219
|
+
return {
|
|
220
|
+
promise: new Promise((res, rej) => {
|
|
221
|
+
resolve = res;
|
|
222
|
+
reject = rej;
|
|
223
|
+
}),
|
|
224
|
+
resolve,
|
|
225
|
+
reject
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const random = Math.random.bind(Math);
|
|
229
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
230
|
+
function nanoid(size = 21) {
|
|
231
|
+
let id = "";
|
|
232
|
+
let i = size;
|
|
233
|
+
while (i--) id += urlAlphabet[random() * 64 | 0];
|
|
234
|
+
return id;
|
|
235
|
+
}
|
|
236
|
+
const DEFAULT_TIMEOUT = 6e4;
|
|
237
|
+
const defaultSerialize = (i) => i;
|
|
238
|
+
const defaultDeserialize = defaultSerialize;
|
|
239
|
+
const { clearTimeout: clearTimeout$1, setTimeout: setTimeout$1 } = globalThis;
|
|
240
|
+
function createBirpc($functions, options) {
|
|
241
|
+
const { post, on, off = () => {}, eventNames = [], serialize = defaultSerialize, deserialize = defaultDeserialize, resolver, bind = "rpc", timeout = DEFAULT_TIMEOUT, proxify = true } = options;
|
|
242
|
+
let $closed = false;
|
|
243
|
+
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
244
|
+
let _promiseInit;
|
|
245
|
+
let rpc;
|
|
246
|
+
async function _call(method, args, event, optional) {
|
|
247
|
+
if ($closed) throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
248
|
+
const req = {
|
|
249
|
+
m: method,
|
|
250
|
+
a: args,
|
|
251
|
+
t: TYPE_REQUEST
|
|
252
|
+
};
|
|
253
|
+
if (optional) req.o = true;
|
|
254
|
+
const send = async (_req) => post(serialize(_req));
|
|
255
|
+
if (event) {
|
|
256
|
+
await send(req);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (_promiseInit) try {
|
|
260
|
+
await _promiseInit;
|
|
261
|
+
} finally {
|
|
262
|
+
_promiseInit = void 0;
|
|
263
|
+
}
|
|
264
|
+
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
265
|
+
const id = nanoid();
|
|
266
|
+
req.i = id;
|
|
267
|
+
let timeoutId;
|
|
268
|
+
async function handler(newReq = req) {
|
|
269
|
+
if (timeout >= 0) {
|
|
270
|
+
timeoutId = setTimeout$1(() => {
|
|
271
|
+
try {
|
|
272
|
+
if (options.onTimeoutError?.call(rpc, method, args) !== true) throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
reject(e);
|
|
275
|
+
}
|
|
276
|
+
_rpcPromiseMap.delete(id);
|
|
277
|
+
}, timeout);
|
|
278
|
+
if (typeof timeoutId === "object") timeoutId = timeoutId.unref?.();
|
|
279
|
+
}
|
|
280
|
+
_rpcPromiseMap.set(id, {
|
|
281
|
+
resolve,
|
|
282
|
+
reject,
|
|
283
|
+
timeoutId,
|
|
284
|
+
method
|
|
285
|
+
});
|
|
286
|
+
await send(newReq);
|
|
287
|
+
return promise;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
if (options.onRequest) await options.onRequest.call(rpc, req, handler, resolve);
|
|
291
|
+
else await handler();
|
|
292
|
+
} catch (e) {
|
|
293
|
+
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
294
|
+
return;
|
|
295
|
+
} finally {
|
|
296
|
+
clearTimeout$1(timeoutId);
|
|
297
|
+
_rpcPromiseMap.delete(id);
|
|
298
|
+
}
|
|
299
|
+
return promise;
|
|
300
|
+
}
|
|
301
|
+
const builtinMethods = {
|
|
302
|
+
$call: (method, ...args) => _call(method, args, false),
|
|
303
|
+
$callOptional: (method, ...args) => _call(method, args, false, true),
|
|
304
|
+
$callEvent: (method, ...args) => _call(method, args, true),
|
|
305
|
+
$callRaw: (options$1) => _call(options$1.method, options$1.args, options$1.event, options$1.optional),
|
|
306
|
+
$rejectPendingCalls,
|
|
307
|
+
get $closed() {
|
|
308
|
+
return $closed;
|
|
309
|
+
},
|
|
310
|
+
get $meta() {
|
|
311
|
+
return options.meta;
|
|
312
|
+
},
|
|
313
|
+
$close,
|
|
314
|
+
$functions
|
|
315
|
+
};
|
|
316
|
+
if (proxify) rpc = new Proxy({}, { get(_, method) {
|
|
317
|
+
if (Object.prototype.hasOwnProperty.call(builtinMethods, method)) return builtinMethods[method];
|
|
318
|
+
if (method === "then" && !eventNames.includes("then") && !("then" in $functions)) return void 0;
|
|
319
|
+
const sendEvent = (...args) => _call(method, args, true);
|
|
320
|
+
if (eventNames.includes(method)) {
|
|
321
|
+
sendEvent.asEvent = sendEvent;
|
|
322
|
+
return sendEvent;
|
|
323
|
+
}
|
|
324
|
+
const sendCall = (...args) => _call(method, args, false);
|
|
325
|
+
sendCall.asEvent = sendEvent;
|
|
326
|
+
return sendCall;
|
|
327
|
+
} });
|
|
328
|
+
else rpc = builtinMethods;
|
|
329
|
+
function $close(customError) {
|
|
330
|
+
$closed = true;
|
|
331
|
+
_rpcPromiseMap.forEach(({ reject, method }) => {
|
|
332
|
+
const error = /* @__PURE__ */ new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
333
|
+
if (customError) {
|
|
334
|
+
customError.cause ??= error;
|
|
335
|
+
return reject(customError);
|
|
336
|
+
}
|
|
337
|
+
reject(error);
|
|
338
|
+
});
|
|
339
|
+
_rpcPromiseMap.clear();
|
|
340
|
+
off(onMessage);
|
|
341
|
+
}
|
|
342
|
+
function $rejectPendingCalls(handler) {
|
|
343
|
+
const handlerResults = Array.from(_rpcPromiseMap.values()).map(({ method, reject }) => {
|
|
344
|
+
if (!handler) return reject(/* @__PURE__ */ new Error(`[birpc]: rejected pending call "${method}".`));
|
|
345
|
+
return handler({
|
|
346
|
+
method,
|
|
347
|
+
reject
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
_rpcPromiseMap.clear();
|
|
351
|
+
return handlerResults;
|
|
352
|
+
}
|
|
353
|
+
async function onMessage(data, ...extra) {
|
|
354
|
+
let msg;
|
|
355
|
+
try {
|
|
356
|
+
msg = deserialize(data);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (msg.t === TYPE_REQUEST) {
|
|
362
|
+
const { m: method, a: args, o: optional } = msg;
|
|
363
|
+
let result, error;
|
|
364
|
+
let fn = await (resolver ? resolver.call(rpc, method, $functions[method]) : $functions[method]);
|
|
365
|
+
if (optional) fn ||= () => void 0;
|
|
366
|
+
if (!fn) error = /* @__PURE__ */ new Error(`[birpc] function "${method}" not found`);
|
|
367
|
+
else try {
|
|
368
|
+
result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
|
|
369
|
+
} catch (e) {
|
|
370
|
+
error = e;
|
|
371
|
+
}
|
|
372
|
+
if (msg.i) {
|
|
373
|
+
if (error && options.onFunctionError) {
|
|
374
|
+
if (options.onFunctionError.call(rpc, error, method, args) === true) return;
|
|
375
|
+
}
|
|
376
|
+
if (!error) try {
|
|
377
|
+
await post(serialize({
|
|
378
|
+
t: TYPE_RESPONSE,
|
|
379
|
+
i: msg.i,
|
|
380
|
+
r: result
|
|
381
|
+
}), ...extra);
|
|
382
|
+
return;
|
|
383
|
+
} catch (e) {
|
|
384
|
+
error = e;
|
|
385
|
+
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
await post(serialize({
|
|
389
|
+
t: TYPE_RESPONSE,
|
|
390
|
+
i: msg.i,
|
|
391
|
+
e: error
|
|
392
|
+
}), ...extra);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
const { i: ack, r: result, e: error } = msg;
|
|
399
|
+
const promise = _rpcPromiseMap.get(ack);
|
|
400
|
+
if (promise) {
|
|
401
|
+
clearTimeout$1(promise.timeoutId);
|
|
402
|
+
if (error) promise.reject(error);
|
|
403
|
+
else promise.resolve(result);
|
|
404
|
+
}
|
|
405
|
+
_rpcPromiseMap.delete(ack);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
_promiseInit = on(onMessage);
|
|
409
|
+
return rpc;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region ../../node_modules/.pnpm/fast-equals@6.0.0/node_modules/fast-equals/dist/es/index.mjs
|
|
414
|
+
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
415
|
+
const { hasOwnProperty } = Object.prototype;
|
|
416
|
+
/**
|
|
417
|
+
* Combine two comparators into a single comparators.
|
|
418
|
+
*/
|
|
419
|
+
function combineComparators(comparatorA, comparatorB) {
|
|
420
|
+
return function isEqual(a, b, state) {
|
|
421
|
+
return comparatorA(a, b, state) && comparatorB(a, b, state);
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Wrap the provided `areItemsEqual` method to manage the circular state, allowing
|
|
426
|
+
* for circular references to be safely included in the comparison without creating
|
|
427
|
+
* stack overflows.
|
|
428
|
+
*/
|
|
429
|
+
function createIsCircular(areItemsEqual) {
|
|
430
|
+
return function isCircular(a, b, state) {
|
|
431
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return areItemsEqual(a, b, state);
|
|
432
|
+
const { cache } = state;
|
|
433
|
+
const cachedA = cache.get(a);
|
|
434
|
+
const cachedB = cache.get(b);
|
|
435
|
+
if (cachedA && cachedB) return cachedA === b && cachedB === a;
|
|
436
|
+
cache.set(a, b);
|
|
437
|
+
cache.set(b, a);
|
|
438
|
+
const result = areItemsEqual(a, b, state);
|
|
439
|
+
cache.delete(a);
|
|
440
|
+
cache.delete(b);
|
|
441
|
+
return result;
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the properties to strictly examine, which include both own properties that are
|
|
446
|
+
* not enumerable and symbol properties.
|
|
447
|
+
*/
|
|
448
|
+
function getStrictProperties(object) {
|
|
449
|
+
return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Whether the object contains the property passed as an own property.
|
|
453
|
+
*/
|
|
454
|
+
const hasOwn = Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property));
|
|
455
|
+
const PREACT_VNODE = "__v";
|
|
456
|
+
const PREACT_OWNER = "__o";
|
|
457
|
+
const REACT_OWNER = "_owner";
|
|
458
|
+
const { getOwnPropertyDescriptor, keys } = Object;
|
|
459
|
+
/**
|
|
460
|
+
* Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
|
|
461
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
|
|
462
|
+
*
|
|
463
|
+
* @note
|
|
464
|
+
* When available in the environment, this is just a re-export of the global
|
|
465
|
+
* [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) method.
|
|
466
|
+
*/
|
|
467
|
+
const sameValueEqual = Object.is || function sameValueEqual(a, b) {
|
|
468
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* Whether the values passed are equal based on a
|
|
472
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
473
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
474
|
+
*
|
|
475
|
+
* @note
|
|
476
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
477
|
+
* two objects is used.
|
|
478
|
+
*/
|
|
479
|
+
function strictEqual(a, b) {
|
|
480
|
+
return a === b;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Whether the array buffers are equal in value.
|
|
484
|
+
*/
|
|
485
|
+
function areArrayBuffersEqual(a, b) {
|
|
486
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Whether the arrays are equal in value.
|
|
490
|
+
*/
|
|
491
|
+
function areArraysEqual(a, b, state) {
|
|
492
|
+
let index = a.length;
|
|
493
|
+
if (b.length !== index) return false;
|
|
494
|
+
while (index-- > 0) if (!state.equals(a[index], b[index], index, index, a, b, state)) return false;
|
|
495
|
+
return true;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Whether the dataviews are equal in value.
|
|
499
|
+
*/
|
|
500
|
+
function areDataViewsEqual(a, b) {
|
|
501
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength));
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Whether the dates passed are equal in value.
|
|
505
|
+
*/
|
|
506
|
+
function areDatesEqual(a, b) {
|
|
507
|
+
return sameValueEqual(a.getTime(), b.getTime());
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Whether the errors passed are equal in value.
|
|
511
|
+
*/
|
|
512
|
+
function areErrorsEqual(a, b) {
|
|
513
|
+
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Whether the `Map`s are equal in value.
|
|
517
|
+
*/
|
|
518
|
+
function areMapsEqual(a, b, state) {
|
|
519
|
+
const size = a.size;
|
|
520
|
+
if (size !== b.size) return false;
|
|
521
|
+
if (!size) return true;
|
|
522
|
+
const matchedIndices = new Array(size);
|
|
523
|
+
const aIterable = a.entries();
|
|
524
|
+
let aResult;
|
|
525
|
+
let bResult;
|
|
526
|
+
let index = 0;
|
|
527
|
+
while (aResult = aIterable.next()) {
|
|
528
|
+
if (aResult.done) break;
|
|
529
|
+
const bIterable = b.entries();
|
|
530
|
+
let hasMatch = false;
|
|
531
|
+
let matchIndex = 0;
|
|
532
|
+
while (bResult = bIterable.next()) {
|
|
533
|
+
if (bResult.done) break;
|
|
534
|
+
if (matchedIndices[matchIndex]) {
|
|
535
|
+
matchIndex++;
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
const aEntry = aResult.value;
|
|
539
|
+
const bEntry = bResult.value;
|
|
540
|
+
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
|
|
541
|
+
hasMatch = matchedIndices[matchIndex] = true;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
matchIndex++;
|
|
545
|
+
}
|
|
546
|
+
if (!hasMatch) return false;
|
|
547
|
+
index++;
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Whether the objects are equal in value.
|
|
553
|
+
*/
|
|
554
|
+
function areObjectsEqual(a, b, state) {
|
|
555
|
+
const properties = keys(a);
|
|
556
|
+
let index = properties.length;
|
|
557
|
+
if (keys(b).length !== index) return false;
|
|
558
|
+
while (index-- > 0) if (!isPropertyEqual(a, b, state, properties[index])) return false;
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Whether the objects are equal in value with strict property checking.
|
|
563
|
+
*/
|
|
564
|
+
function areObjectsEqualStrict(a, b, state) {
|
|
565
|
+
const properties = getStrictProperties(a);
|
|
566
|
+
let index = properties.length;
|
|
567
|
+
if (getStrictProperties(b).length !== index) return false;
|
|
568
|
+
let property;
|
|
569
|
+
let descriptorA;
|
|
570
|
+
let descriptorB;
|
|
571
|
+
while (index-- > 0) {
|
|
572
|
+
property = properties[index];
|
|
573
|
+
if (!isPropertyEqual(a, b, state, property)) return false;
|
|
574
|
+
descriptorA = getOwnPropertyDescriptor(a, property);
|
|
575
|
+
descriptorB = getOwnPropertyDescriptor(b, property);
|
|
576
|
+
if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) return false;
|
|
577
|
+
}
|
|
578
|
+
return true;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Whether the primitive wrappers passed are equal in value.
|
|
582
|
+
*/
|
|
583
|
+
function arePrimitiveWrappersEqual(a, b) {
|
|
584
|
+
return sameValueEqual(a.valueOf(), b.valueOf());
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Whether the regexps passed are equal in value.
|
|
588
|
+
*/
|
|
589
|
+
function areRegExpsEqual(a, b) {
|
|
590
|
+
return a.source === b.source && a.flags === b.flags;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Whether the `Set`s are equal in value.
|
|
594
|
+
*/
|
|
595
|
+
function areSetsEqual(a, b, state) {
|
|
596
|
+
const size = a.size;
|
|
597
|
+
if (size !== b.size) return false;
|
|
598
|
+
if (!size) return true;
|
|
599
|
+
const matchedIndices = new Array(size);
|
|
600
|
+
const aIterable = a.values();
|
|
601
|
+
let aResult;
|
|
602
|
+
let bResult;
|
|
603
|
+
while (aResult = aIterable.next()) {
|
|
604
|
+
if (aResult.done) break;
|
|
605
|
+
const bIterable = b.values();
|
|
606
|
+
let hasMatch = false;
|
|
607
|
+
let matchIndex = 0;
|
|
608
|
+
while (bResult = bIterable.next()) {
|
|
609
|
+
if (bResult.done) break;
|
|
610
|
+
if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
611
|
+
hasMatch = matchedIndices[matchIndex] = true;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
matchIndex++;
|
|
615
|
+
}
|
|
616
|
+
if (!hasMatch) return false;
|
|
617
|
+
}
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Whether the TypedArray instances are equal in value.
|
|
622
|
+
*/
|
|
623
|
+
function areTypedArraysEqual(a, b) {
|
|
624
|
+
let index = a.byteLength;
|
|
625
|
+
if (b.byteLength !== index || a.byteOffset !== b.byteOffset) return false;
|
|
626
|
+
while (index-- > 0) if (a[index] !== b[index]) return false;
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Whether the URL instances are equal in value.
|
|
631
|
+
*/
|
|
632
|
+
function areUrlsEqual(a, b) {
|
|
633
|
+
return a.hostname === b.hostname && a.pathname === b.pathname && a.protocol === b.protocol && a.port === b.port && a.hash === b.hash && a.username === b.username && a.password === b.password;
|
|
634
|
+
}
|
|
635
|
+
function isPropertyEqual(a, b, state, property) {
|
|
636
|
+
if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) return true;
|
|
637
|
+
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
638
|
+
}
|
|
639
|
+
const toString = Object.prototype.toString;
|
|
640
|
+
/**
|
|
641
|
+
* Create a comparator method based on the type-specific equality comparators passed.
|
|
642
|
+
*/
|
|
643
|
+
function createEqualityComparator(config) {
|
|
644
|
+
const supportedComparatorMap = createSupportedComparatorMap(config);
|
|
645
|
+
const { areArraysEqual, areDatesEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, areRegExpsEqual, areSetsEqual, getUnsupportedCustomComparator } = config;
|
|
646
|
+
/**
|
|
647
|
+
* compare the value of the two objects and return true if they are equivalent in values
|
|
648
|
+
*/
|
|
649
|
+
return function comparator(a, b, state) {
|
|
650
|
+
if (a === b) return true;
|
|
651
|
+
if (a == null || b == null) return false;
|
|
652
|
+
const type = typeof a;
|
|
653
|
+
if (type !== typeof b) return false;
|
|
654
|
+
if (type !== "object") {
|
|
655
|
+
if (type === "number" || type === "bigint") return areNumbersEqual(a, b, state);
|
|
656
|
+
if (type === "function") return areFunctionsEqual(a, b, state);
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
const constructor = a.constructor;
|
|
660
|
+
if (constructor !== b.constructor) return false;
|
|
661
|
+
if (constructor === Object) return areObjectsEqual(a, b, state);
|
|
662
|
+
if (constructor === Array) return areArraysEqual(a, b, state);
|
|
663
|
+
if (constructor === Date) return areDatesEqual(a, b, state);
|
|
664
|
+
if (constructor === RegExp) return areRegExpsEqual(a, b, state);
|
|
665
|
+
if (constructor === Map) return areMapsEqual(a, b, state);
|
|
666
|
+
if (constructor === Set) return areSetsEqual(a, b, state);
|
|
667
|
+
if (constructor === Promise) return false;
|
|
668
|
+
if (Array.isArray(a)) return areArraysEqual(a, b, state);
|
|
669
|
+
const tag = toString.call(a);
|
|
670
|
+
const supportedComparator = supportedComparatorMap[tag];
|
|
671
|
+
if (supportedComparator) return supportedComparator(a, b, state);
|
|
672
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
673
|
+
if (unsupportedCustomComparator) return unsupportedCustomComparator(a, b, state);
|
|
674
|
+
return false;
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Create the configuration object used for building comparators.
|
|
679
|
+
*/
|
|
680
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) {
|
|
681
|
+
let config = {
|
|
682
|
+
areArrayBuffersEqual,
|
|
683
|
+
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
684
|
+
areDataViewsEqual,
|
|
685
|
+
areDatesEqual,
|
|
686
|
+
areErrorsEqual,
|
|
687
|
+
areFunctionsEqual: strictEqual,
|
|
688
|
+
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
689
|
+
areNumbersEqual: sameValueEqual,
|
|
690
|
+
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
691
|
+
arePrimitiveWrappersEqual,
|
|
692
|
+
areRegExpsEqual,
|
|
693
|
+
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
694
|
+
areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual,
|
|
695
|
+
areUrlsEqual,
|
|
696
|
+
getUnsupportedCustomComparator: void 0
|
|
697
|
+
};
|
|
698
|
+
if (createCustomConfig) config = Object.assign({}, config, createCustomConfig(config));
|
|
699
|
+
if (circular) {
|
|
700
|
+
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
701
|
+
const areMapsEqual = createIsCircular(config.areMapsEqual);
|
|
702
|
+
const areObjectsEqual = createIsCircular(config.areObjectsEqual);
|
|
703
|
+
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
704
|
+
config = Object.assign({}, config, {
|
|
705
|
+
areArraysEqual,
|
|
706
|
+
areMapsEqual,
|
|
707
|
+
areObjectsEqual,
|
|
708
|
+
areSetsEqual
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
return config;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Default equality comparator pass-through, used as the standard `isEqual` creator for
|
|
715
|
+
* use inside the built comparator.
|
|
716
|
+
*/
|
|
717
|
+
function createInternalEqualityComparator(compare) {
|
|
718
|
+
return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
|
|
719
|
+
return compare(a, b, state);
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Create the `isEqual` function used by the consuming application.
|
|
724
|
+
*/
|
|
725
|
+
function createIsEqual({ circular, comparator, createState, equals, strict }) {
|
|
726
|
+
if (createState) return function isEqual(a, b) {
|
|
727
|
+
const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState();
|
|
728
|
+
return comparator(a, b, {
|
|
729
|
+
cache,
|
|
730
|
+
equals,
|
|
731
|
+
meta,
|
|
732
|
+
strict
|
|
733
|
+
});
|
|
734
|
+
};
|
|
735
|
+
if (circular) return function isEqual(a, b) {
|
|
736
|
+
return comparator(a, b, {
|
|
737
|
+
cache: /* @__PURE__ */ new WeakMap(),
|
|
738
|
+
equals,
|
|
739
|
+
meta: void 0,
|
|
740
|
+
strict
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
const state = {
|
|
744
|
+
cache: void 0,
|
|
745
|
+
equals,
|
|
746
|
+
meta: void 0,
|
|
747
|
+
strict
|
|
748
|
+
};
|
|
749
|
+
return function isEqual(a, b) {
|
|
750
|
+
return comparator(a, b, state);
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Create a map of `toString()` values to their respective handlers for `tag`-based lookups.
|
|
755
|
+
*/
|
|
756
|
+
function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual }) {
|
|
757
|
+
return {
|
|
758
|
+
"[object Arguments]": areObjectsEqual,
|
|
759
|
+
"[object Array]": areArraysEqual,
|
|
760
|
+
"[object ArrayBuffer]": areArrayBuffersEqual,
|
|
761
|
+
"[object AsyncGeneratorFunction]": areFunctionsEqual,
|
|
762
|
+
"[object BigInt]": areNumbersEqual,
|
|
763
|
+
"[object BigInt64Array]": areTypedArraysEqual,
|
|
764
|
+
"[object BigUint64Array]": areTypedArraysEqual,
|
|
765
|
+
"[object Boolean]": arePrimitiveWrappersEqual,
|
|
766
|
+
"[object DataView]": areDataViewsEqual,
|
|
767
|
+
"[object Date]": areDatesEqual,
|
|
768
|
+
"[object Error]": areErrorsEqual,
|
|
769
|
+
"[object Float16Array]": areTypedArraysEqual,
|
|
770
|
+
"[object Float32Array]": areTypedArraysEqual,
|
|
771
|
+
"[object Float64Array]": areTypedArraysEqual,
|
|
772
|
+
"[object Function]": areFunctionsEqual,
|
|
773
|
+
"[object GeneratorFunction]": areFunctionsEqual,
|
|
774
|
+
"[object Int8Array]": areTypedArraysEqual,
|
|
775
|
+
"[object Int16Array]": areTypedArraysEqual,
|
|
776
|
+
"[object Int32Array]": areTypedArraysEqual,
|
|
777
|
+
"[object Map]": areMapsEqual,
|
|
778
|
+
"[object Number]": arePrimitiveWrappersEqual,
|
|
779
|
+
"[object Object]": (a, b, state) => typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual(a, b, state),
|
|
780
|
+
"[object RegExp]": areRegExpsEqual,
|
|
781
|
+
"[object Set]": areSetsEqual,
|
|
782
|
+
"[object String]": arePrimitiveWrappersEqual,
|
|
783
|
+
"[object URL]": areUrlsEqual,
|
|
784
|
+
"[object Uint8Array]": areTypedArraysEqual,
|
|
785
|
+
"[object Uint8ClampedArray]": areTypedArraysEqual,
|
|
786
|
+
"[object Uint16Array]": areTypedArraysEqual,
|
|
787
|
+
"[object Uint32Array]": areTypedArraysEqual
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Whether the items passed are deeply-equal in value.
|
|
792
|
+
*/
|
|
793
|
+
const deepEqual = createCustomEqual();
|
|
794
|
+
/**
|
|
795
|
+
* Whether the items passed are deeply-equal in value based on strict comparison.
|
|
796
|
+
*/
|
|
797
|
+
const strictDeepEqual = createCustomEqual({ strict: true });
|
|
798
|
+
/**
|
|
799
|
+
* Whether the items passed are deeply-equal in value, including circular references.
|
|
800
|
+
*/
|
|
801
|
+
const circularDeepEqual = createCustomEqual({ circular: true });
|
|
802
|
+
/**
|
|
803
|
+
* Whether the items passed are deeply-equal in value, including circular references,
|
|
804
|
+
* based on strict comparison.
|
|
805
|
+
*/
|
|
806
|
+
const strictCircularDeepEqual = createCustomEqual({
|
|
807
|
+
circular: true,
|
|
808
|
+
strict: true
|
|
809
|
+
});
|
|
810
|
+
/**
|
|
811
|
+
* Whether the items passed are shallowly-equal in value.
|
|
812
|
+
*/
|
|
813
|
+
const shallowEqual = createCustomEqual({ createInternalComparator: () => sameValueEqual });
|
|
814
|
+
/**
|
|
815
|
+
* Whether the items passed are shallowly-equal in value based on strict comparison
|
|
816
|
+
*/
|
|
817
|
+
const strictShallowEqual = createCustomEqual({
|
|
818
|
+
strict: true,
|
|
819
|
+
createInternalComparator: () => sameValueEqual
|
|
820
|
+
});
|
|
821
|
+
/**
|
|
822
|
+
* Whether the items passed are shallowly-equal in value, including circular references.
|
|
823
|
+
*/
|
|
824
|
+
const circularShallowEqual = createCustomEqual({
|
|
825
|
+
circular: true,
|
|
826
|
+
createInternalComparator: () => sameValueEqual
|
|
827
|
+
});
|
|
828
|
+
/**
|
|
829
|
+
* Whether the items passed are shallowly-equal in value, including circular references,
|
|
830
|
+
* based on strict comparison.
|
|
831
|
+
*/
|
|
832
|
+
const strictCircularShallowEqual = createCustomEqual({
|
|
833
|
+
circular: true,
|
|
834
|
+
createInternalComparator: () => sameValueEqual,
|
|
835
|
+
strict: true
|
|
836
|
+
});
|
|
837
|
+
/**
|
|
838
|
+
* Create a custom equality comparison method.
|
|
839
|
+
*
|
|
840
|
+
* This can be done to create very targeted comparisons in extreme hot-path scenarios
|
|
841
|
+
* where the standard methods are not performant enough, but can also be used to provide
|
|
842
|
+
* support for legacy environments that do not support expected features like
|
|
843
|
+
* `RegExp.prototype.flags` out of the box.
|
|
844
|
+
*/
|
|
845
|
+
function createCustomEqual(options = {}) {
|
|
846
|
+
const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options;
|
|
847
|
+
const comparator = createEqualityComparator(createEqualityComparatorConfig(options));
|
|
848
|
+
return createIsEqual({
|
|
849
|
+
circular,
|
|
850
|
+
comparator,
|
|
851
|
+
createState,
|
|
852
|
+
equals: createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator),
|
|
853
|
+
strict
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region ../../node_modules/.pnpm/remeda@2.37.0/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
|
|
859
|
+
function e(e, t, n) {
|
|
860
|
+
let r = (n) => e(n, ...t);
|
|
861
|
+
return n === void 0 ? r : Object.assign(r, {
|
|
862
|
+
lazy: n,
|
|
863
|
+
lazyArgs: t
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
//#endregion
|
|
868
|
+
//#region ../../node_modules/.pnpm/remeda@2.37.0/node_modules/remeda/dist/purry.js
|
|
869
|
+
function t$1(t, n, r) {
|
|
870
|
+
let i = t.length - n.length;
|
|
871
|
+
if (i === 0) return t(...n);
|
|
872
|
+
if (i === 1) return e(t, n, r);
|
|
873
|
+
throw Error(`Wrong number of arguments`);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
//#endregion
|
|
877
|
+
//#region ../../node_modules/.pnpm/remeda@2.37.0/node_modules/remeda/dist/mapValues.js
|
|
878
|
+
function t(...t) {
|
|
879
|
+
return t$1(n, t);
|
|
880
|
+
}
|
|
881
|
+
function n(e, t) {
|
|
882
|
+
let n = {};
|
|
883
|
+
for (let [r, i] of Object.entries(e)) n[r] = t(i, r, e);
|
|
884
|
+
return n;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region ../vite-plugin/src/internal.ts
|
|
889
|
+
/**
|
|
890
|
+
* This module is used by the Vite plugin to generate the virtual modules
|
|
891
|
+
*/
|
|
892
|
+
/**
|
|
893
|
+
* Create a PluginRPC instance for the LikeC4 Vite plugin
|
|
894
|
+
* used by the Vite plugin in virtual modules
|
|
895
|
+
*/
|
|
896
|
+
function createRpc(options) {
|
|
897
|
+
return createBirpc({}, {
|
|
898
|
+
timeout: 120 * 1e3,
|
|
899
|
+
post: (data) => options.send("likec4:rpc", data),
|
|
900
|
+
on: (fn) => options.on("likec4:rpc", fn),
|
|
901
|
+
onTimeoutError(functionName) {
|
|
902
|
+
return functionName === "applySemanticLayout";
|
|
903
|
+
},
|
|
904
|
+
onGeneralError(error, functionName) {
|
|
905
|
+
console.error(`RPC error in ${functionName}`, { error });
|
|
906
|
+
},
|
|
907
|
+
onFunctionError: (error, functionName) => {
|
|
908
|
+
console.error(`RPC error in ${functionName}`, { error });
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
function createHooksForModel($atom) {
|
|
913
|
+
const $likec4model = /* @__PURE__ */ computed($atom, (data) => LikeC4Model.create(data));
|
|
914
|
+
function updateModel(data) {
|
|
915
|
+
const current = $atom.get();
|
|
916
|
+
const next = {
|
|
917
|
+
...data,
|
|
918
|
+
views: t(data.views, (next) => {
|
|
919
|
+
const currentView = current.views[next.id];
|
|
920
|
+
return deepEqual(currentView, next) ? currentView : next;
|
|
921
|
+
})
|
|
922
|
+
};
|
|
923
|
+
if (shallowEqual(next.views, current.views) && deepEqual(next, current)) return;
|
|
924
|
+
$atom.set(next);
|
|
925
|
+
}
|
|
926
|
+
const $likec4views = /* @__PURE__ */ computed($likec4model, (model) => [...model.views()].map((v) => v.$layouted));
|
|
927
|
+
function useLikeC4Model() {
|
|
928
|
+
return useStore($likec4model);
|
|
929
|
+
}
|
|
930
|
+
function useLikeC4Views() {
|
|
931
|
+
return useStore($likec4views);
|
|
932
|
+
}
|
|
933
|
+
function useLikeC4View(viewId) {
|
|
934
|
+
return useStore(useMemo(() => /* @__PURE__ */ computed($likec4model, (model) => model.findView(viewId)?.$layouted ?? null), [viewId]));
|
|
935
|
+
}
|
|
936
|
+
return {
|
|
937
|
+
updateModel,
|
|
938
|
+
$likec4model,
|
|
939
|
+
useLikeC4Model,
|
|
940
|
+
useLikeC4Views,
|
|
941
|
+
useLikeC4View
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
//#endregion
|
|
946
|
+
export { atom, batched, computed, createHooksForModel, createRpc, map, useStore };
|