@fivem-nui/svelte 0.0.0-stage → 1.0.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/README.md +284 -2
- package/dist/actions/clickOutside/clickOutside.d.ts +24 -0
- package/dist/actions/clickOutside/clickOutside.d.ts.map +1 -0
- package/dist/actions/clickOutside/clickOutside.js +62 -0
- package/dist/actions/clickOutside/clickOutside.js.map +1 -0
- package/dist/actions/clickOutside/handler.d.ts +11 -0
- package/dist/actions/clickOutside/handler.d.ts.map +1 -0
- package/dist/actions/clickOutside/handler.js +45 -0
- package/dist/actions/clickOutside/handler.js.map +1 -0
- package/dist/actions/clickOutside/index.d.ts +4 -0
- package/dist/actions/clickOutside/index.d.ts.map +1 -0
- package/dist/actions/clickOutside/index.js +4 -0
- package/dist/actions/clickOutside/index.js.map +1 -0
- package/dist/actions/clickOutside/types.d.ts +36 -0
- package/dist/actions/clickOutside/types.d.ts.map +1 -0
- package/dist/actions/clickOutside/types.js +6 -0
- package/dist/actions/clickOutside/types.js.map +1 -0
- package/dist/actions/clickOutside.d.ts +63 -0
- package/dist/actions/clickOutside.d.ts.map +1 -0
- package/dist/actions/clickOutside.js +106 -0
- package/dist/actions/clickOutside.js.map +1 -0
- package/dist/actions/escape/escape.d.ts +26 -0
- package/dist/actions/escape/escape.d.ts.map +1 -0
- package/dist/actions/escape/escape.js +74 -0
- package/dist/actions/escape/escape.js.map +1 -0
- package/dist/actions/escape/handler.d.ts +11 -0
- package/dist/actions/escape/handler.d.ts.map +1 -0
- package/dist/actions/escape/handler.js +50 -0
- package/dist/actions/escape/handler.js.map +1 -0
- package/dist/actions/escape/index.d.ts +4 -0
- package/dist/actions/escape/index.d.ts.map +1 -0
- package/dist/actions/escape/index.js +4 -0
- package/dist/actions/escape/index.js.map +1 -0
- package/dist/actions/escape/types.d.ts +70 -0
- package/dist/actions/escape/types.d.ts.map +1 -0
- package/dist/actions/escape/types.js +12 -0
- package/dist/actions/escape/types.js.map +1 -0
- package/dist/actions/escape.d.ts +99 -0
- package/dist/actions/escape.d.ts.map +1 -0
- package/dist/actions/escape.js +128 -0
- package/dist/actions/escape.js.map +1 -0
- package/dist/actions/focusTrap/focusTrap.d.ts +19 -0
- package/dist/actions/focusTrap/focusTrap.d.ts.map +1 -0
- package/dist/actions/focusTrap/focusTrap.js +198 -0
- package/dist/actions/focusTrap/focusTrap.js.map +1 -0
- package/dist/actions/focusTrap/focusables.d.ts +39 -0
- package/dist/actions/focusTrap/focusables.d.ts.map +1 -0
- package/dist/actions/focusTrap/focusables.js +142 -0
- package/dist/actions/focusTrap/focusables.js.map +1 -0
- package/dist/actions/focusTrap/index.d.ts +5 -0
- package/dist/actions/focusTrap/index.d.ts.map +1 -0
- package/dist/actions/focusTrap/index.js +5 -0
- package/dist/actions/focusTrap/index.js.map +1 -0
- package/dist/actions/focusTrap/trapStack.d.ts +33 -0
- package/dist/actions/focusTrap/trapStack.d.ts.map +1 -0
- package/dist/actions/focusTrap/trapStack.js +84 -0
- package/dist/actions/focusTrap/trapStack.js.map +1 -0
- package/dist/actions/focusTrap/types.d.ts +50 -0
- package/dist/actions/focusTrap/types.d.ts.map +1 -0
- package/dist/actions/focusTrap/types.js +10 -0
- package/dist/actions/focusTrap/types.js.map +1 -0
- package/dist/actions/focusTrap.d.ts +24 -0
- package/dist/actions/focusTrap.d.ts.map +1 -0
- package/dist/actions/focusTrap.js +201 -0
- package/dist/actions/focusTrap.js.map +1 -0
- package/dist/actions/focusTrap.types.d.ts +50 -0
- package/dist/actions/focusTrap.types.d.ts.map +1 -0
- package/dist/actions/focusTrap.types.js +10 -0
- package/dist/actions/focusTrap.types.js.map +1 -0
- package/dist/actions/focusables.d.ts +39 -0
- package/dist/actions/focusables.d.ts.map +1 -0
- package/dist/actions/focusables.js +142 -0
- package/dist/actions/focusables.js.map +1 -0
- package/dist/actions/index.d.ts +5 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +5 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/layer/index.d.ts +4 -0
- package/dist/actions/layer/index.d.ts.map +1 -0
- package/dist/actions/layer/index.js +4 -0
- package/dist/actions/layer/index.js.map +1 -0
- package/dist/actions/layer/layer.d.ts +28 -0
- package/dist/actions/layer/layer.d.ts.map +1 -0
- package/dist/actions/layer/layer.js +118 -0
- package/dist/actions/layer/layer.js.map +1 -0
- package/dist/actions/layer/layerStack.d.ts +10 -0
- package/dist/actions/layer/layerStack.d.ts.map +1 -0
- package/dist/actions/layer/layerStack.js +153 -0
- package/dist/actions/layer/layerStack.js.map +1 -0
- package/dist/actions/layer/types.d.ts +105 -0
- package/dist/actions/layer/types.d.ts.map +1 -0
- package/dist/actions/layer/types.js +14 -0
- package/dist/actions/layer/types.js.map +1 -0
- package/dist/actions/layer.d.ts +133 -0
- package/dist/actions/layer.d.ts.map +1 -0
- package/dist/actions/layer.js +269 -0
- package/dist/actions/layer.js.map +1 -0
- package/dist/actions/trapStack.d.ts +33 -0
- package/dist/actions/trapStack.d.ts.map +1 -0
- package/dist/actions/trapStack.js +84 -0
- package/dist/actions/trapStack.js.map +1 -0
- package/dist/client.d.ts +179 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +176 -0
- package/dist/client.js.map +1 -0
- package/dist/context/index.d.ts +68 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +112 -0
- package/dist/context/index.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/mock/index.d.ts +27 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +137 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/interceptor.d.ts +19 -0
- package/dist/mock/interceptor.d.ts.map +1 -0
- package/dist/mock/interceptor.js +128 -0
- package/dist/mock/interceptor.js.map +1 -0
- package/dist/mock/types.d.ts +100 -0
- package/dist/mock/types.d.ts.map +1 -0
- package/dist/mock/types.js +27 -0
- package/dist/mock/types.js.map +1 -0
- package/dist/mock/url.d.ts +14 -0
- package/dist/mock/url.d.ts.map +1 -0
- package/dist/mock/url.js +38 -0
- package/dist/mock/url.js.map +1 -0
- package/dist/runes/clickOutside.svelte.d.ts +29 -0
- package/dist/runes/clickOutside.svelte.d.ts.map +1 -0
- package/dist/runes/clickOutside.svelte.js +42 -0
- package/dist/runes/clickOutside.svelte.js.map +1 -0
- package/dist/runes/escape.svelte.d.ts +34 -0
- package/dist/runes/escape.svelte.d.ts.map +1 -0
- package/dist/runes/escape.svelte.js +44 -0
- package/dist/runes/escape.svelte.js.map +1 -0
- package/dist/runes/focusTrap.svelte.d.ts +21 -0
- package/dist/runes/focusTrap.svelte.d.ts.map +1 -0
- package/dist/runes/focusTrap.svelte.js +37 -0
- package/dist/runes/focusTrap.svelte.js.map +1 -0
- package/dist/runes/index.svelte.d.ts +8 -0
- package/dist/runes/index.svelte.d.ts.map +1 -0
- package/dist/runes/index.svelte.js +8 -0
- package/dist/runes/index.svelte.js.map +1 -0
- package/dist/runes/layer.svelte.d.ts +36 -0
- package/dist/runes/layer.svelte.d.ts.map +1 -0
- package/dist/runes/layer.svelte.js +48 -0
- package/dist/runes/layer.svelte.js.map +1 -0
- package/dist/runes/query.svelte.d.ts +104 -0
- package/dist/runes/query.svelte.d.ts.map +1 -0
- package/dist/runes/query.svelte.js +179 -0
- package/dist/runes/query.svelte.js.map +1 -0
- package/dist/runes/state.svelte.d.ts +72 -0
- package/dist/runes/state.svelte.d.ts.map +1 -0
- package/dist/runes/state.svelte.js +98 -0
- package/dist/runes/state.svelte.js.map +1 -0
- package/dist/runes/window.svelte.d.ts +120 -0
- package/dist/runes/window.svelte.d.ts.map +1 -0
- package/dist/runes/window.svelte.js +196 -0
- package/dist/runes/window.svelte.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/nui.d.ts +34 -0
- package/dist/types/nui.d.ts.map +1 -0
- package/dist/types/nui.js +17 -0
- package/dist/types/nui.js.map +1 -0
- package/dist/utils/env.d.ts +21 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +36 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/error.d.ts +11 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +30 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/keyboard.d.ts +127 -0
- package/dist/utils/keyboard.d.ts.map +1 -0
- package/dist/utils/keyboard.js +152 -0
- package/dist/utils/keyboard.js.map +1 -0
- package/package.json +76 -4
- package/src/actions/clickOutside/clickOutside.ts +78 -0
- package/src/actions/clickOutside/handler.ts +49 -0
- package/src/actions/clickOutside/index.ts +11 -0
- package/src/actions/clickOutside/types.ts +54 -0
- package/src/actions/escape/escape.ts +90 -0
- package/src/actions/escape/handler.ts +52 -0
- package/src/actions/escape/index.ts +11 -0
- package/src/actions/escape/types.ts +88 -0
- package/src/actions/focusTrap/focusTrap.ts +228 -0
- package/src/actions/focusTrap/focusables.ts +155 -0
- package/src/actions/focusTrap/index.ts +22 -0
- package/src/actions/focusTrap/trapStack.ts +109 -0
- package/src/actions/focusTrap/types.ts +64 -0
- package/src/actions/index.ts +35 -0
- package/src/actions/layer/index.ts +13 -0
- package/src/actions/layer/layer.ts +140 -0
- package/src/actions/layer/layerStack.ts +169 -0
- package/src/actions/layer/types.ts +132 -0
- package/src/client.ts +323 -0
- package/src/context/index.ts +127 -0
- package/src/index.ts +53 -0
- package/src/mock/index.ts +176 -0
- package/src/mock/interceptor.ts +177 -0
- package/src/mock/types.ts +125 -0
- package/src/mock/url.ts +37 -0
- package/src/runes/clickOutside.svelte.ts +53 -0
- package/src/runes/escape.svelte.ts +71 -0
- package/src/runes/focusTrap.svelte.ts +56 -0
- package/src/runes/index.svelte.ts +38 -0
- package/src/runes/layer.svelte.ts +74 -0
- package/src/runes/query.svelte.ts +313 -0
- package/src/runes/state.svelte.ts +175 -0
- package/src/runes/window.svelte.ts +308 -0
- package/src/utils/env.ts +36 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/keyboard.ts +244 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { onDestroy } from 'svelte';
|
|
2
|
+
import { globalErrorHandler } from '@fivem-nui/error';
|
|
3
|
+
import { useNuiClient } from '../context';
|
|
4
|
+
/**
|
|
5
|
+
* Window lifecycle actions dispatched from C# backend to NUI UI.
|
|
6
|
+
*/
|
|
7
|
+
export var NuiWindowActionType;
|
|
8
|
+
(function (NuiWindowActionType) {
|
|
9
|
+
NuiWindowActionType["Open"] = "open";
|
|
10
|
+
NuiWindowActionType["Close"] = "close";
|
|
11
|
+
NuiWindowActionType["Focus"] = "focus";
|
|
12
|
+
NuiWindowActionType["Unfocus"] = "unfocus";
|
|
13
|
+
})(NuiWindowActionType || (NuiWindowActionType = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Window lifecycle notifications dispatched from UI to C# backend.
|
|
16
|
+
*/
|
|
17
|
+
export var NuiWindowNotification;
|
|
18
|
+
(function (NuiWindowNotification) {
|
|
19
|
+
NuiWindowNotification["Ready"] = "ready";
|
|
20
|
+
NuiWindowNotification["Close"] = "close";
|
|
21
|
+
})(NuiWindowNotification || (NuiWindowNotification = {}));
|
|
22
|
+
function safeCallback(operation, callback, ...args) {
|
|
23
|
+
if (!callback)
|
|
24
|
+
return;
|
|
25
|
+
try {
|
|
26
|
+
callback(...args);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
void globalErrorHandler
|
|
30
|
+
.handle(error instanceof Error ? error : new Error(String(error)), { args }, operation)
|
|
31
|
+
.catch(() => { });
|
|
32
|
+
console.error(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Controller managing reactive visibility, focus, and backend events for a named NUI window.
|
|
37
|
+
*/
|
|
38
|
+
export class NuiWindowController {
|
|
39
|
+
windowName;
|
|
40
|
+
options;
|
|
41
|
+
client;
|
|
42
|
+
visible = $state(false);
|
|
43
|
+
focused = $state(false);
|
|
44
|
+
destroyed = false;
|
|
45
|
+
listeningForEscape = false;
|
|
46
|
+
unsubscribe;
|
|
47
|
+
constructor(windowName, options = {}, client) {
|
|
48
|
+
this.windowName = windowName;
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.client = client;
|
|
51
|
+
this.visible = options.initialVisible ?? false;
|
|
52
|
+
this.unsubscribe = client.onWindow(this.handleWindowAction);
|
|
53
|
+
if (this.visible) {
|
|
54
|
+
this.syncEscapeListener(true);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
syncEscapeListener(shouldListen) {
|
|
58
|
+
if (typeof window === 'undefined' || this.options.closeOnEscape === false)
|
|
59
|
+
return;
|
|
60
|
+
if (this.listeningForEscape === shouldListen)
|
|
61
|
+
return;
|
|
62
|
+
if (shouldListen) {
|
|
63
|
+
window.addEventListener('keydown', this.handleEscape);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
window.removeEventListener('keydown', this.handleEscape);
|
|
67
|
+
}
|
|
68
|
+
this.listeningForEscape = shouldListen;
|
|
69
|
+
}
|
|
70
|
+
handleEscape = (event) => {
|
|
71
|
+
if (event.key !== 'Escape' || !this.visible || this.destroyed)
|
|
72
|
+
return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
this.close();
|
|
75
|
+
};
|
|
76
|
+
transition(nextVisible, nextFocused) {
|
|
77
|
+
const changes = {
|
|
78
|
+
visibility: nextVisible !== undefined && this.visible !== nextVisible,
|
|
79
|
+
focus: nextFocused !== undefined && this.focused !== nextFocused
|
|
80
|
+
};
|
|
81
|
+
if (nextVisible !== undefined && changes.visibility) {
|
|
82
|
+
this.visible = nextVisible;
|
|
83
|
+
this.syncEscapeListener(nextVisible);
|
|
84
|
+
}
|
|
85
|
+
if (nextFocused !== undefined && changes.focus) {
|
|
86
|
+
this.focused = nextFocused;
|
|
87
|
+
}
|
|
88
|
+
return changes;
|
|
89
|
+
}
|
|
90
|
+
notifyAndDispatch(changes, notification) {
|
|
91
|
+
if (notification && (changes.visibility || changes.focus)) {
|
|
92
|
+
try {
|
|
93
|
+
this.client.notify(notification, { window: this.windowName });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
void globalErrorHandler
|
|
97
|
+
.handle(error instanceof Error ? error : new Error(String(error)), { window: this.windowName, notification }, 'useNuiWindow:notify')
|
|
98
|
+
.catch(() => { });
|
|
99
|
+
console.error('[NuiWindow] Failed to dispatch notify to backend:', error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (changes.visibility) {
|
|
103
|
+
safeCallback('useNuiWindow:visibility', this.visible ? this.options.onOpen : this.options.onClose);
|
|
104
|
+
}
|
|
105
|
+
if (changes.focus) {
|
|
106
|
+
safeCallback('useNuiWindow:focus', this.options.onFocusChange, this.focused);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
open = () => {
|
|
110
|
+
if (this.destroyed)
|
|
111
|
+
return;
|
|
112
|
+
const changes = this.transition(true, true);
|
|
113
|
+
this.notifyAndDispatch(changes, NuiWindowNotification.Ready);
|
|
114
|
+
};
|
|
115
|
+
close = () => {
|
|
116
|
+
if (this.destroyed)
|
|
117
|
+
return;
|
|
118
|
+
const changes = this.transition(false, false);
|
|
119
|
+
this.notifyAndDispatch(changes, NuiWindowNotification.Close);
|
|
120
|
+
};
|
|
121
|
+
toggle = () => {
|
|
122
|
+
if (this.destroyed)
|
|
123
|
+
return;
|
|
124
|
+
if (this.visible)
|
|
125
|
+
this.close();
|
|
126
|
+
else
|
|
127
|
+
this.open();
|
|
128
|
+
};
|
|
129
|
+
handleWindowAction = (action, targetWindow) => {
|
|
130
|
+
if (this.destroyed || (targetWindow && targetWindow !== this.windowName)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
switch (action) {
|
|
134
|
+
case NuiWindowActionType.Open:
|
|
135
|
+
this.notifyAndDispatch(this.transition(true, true));
|
|
136
|
+
break;
|
|
137
|
+
case NuiWindowActionType.Close:
|
|
138
|
+
this.notifyAndDispatch(this.transition(false, false));
|
|
139
|
+
break;
|
|
140
|
+
case NuiWindowActionType.Focus:
|
|
141
|
+
if (this.visible) {
|
|
142
|
+
this.notifyAndDispatch(this.transition(undefined, true));
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case NuiWindowActionType.Unfocus:
|
|
146
|
+
this.notifyAndDispatch(this.transition(undefined, false));
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
destroy = () => {
|
|
151
|
+
if (this.destroyed)
|
|
152
|
+
return;
|
|
153
|
+
this.destroyed = true;
|
|
154
|
+
this.syncEscapeListener(false);
|
|
155
|
+
this.unsubscribe();
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Reactive controller for a named NUI window.
|
|
160
|
+
* Synchronizes visibility and focus states with the FiveM C# backend.
|
|
161
|
+
*
|
|
162
|
+
* @param windowName - Window identifier matching backend events.
|
|
163
|
+
* @param options - Optional configuration (callbacks, Escape handling).
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```svelte
|
|
167
|
+
* <script>
|
|
168
|
+
* import { useNuiWindow } from '@fivem-nui/svelte';
|
|
169
|
+
*
|
|
170
|
+
* const win = useNuiWindow('inventory', { closeOnEscape: true });
|
|
171
|
+
* </script>
|
|
172
|
+
*
|
|
173
|
+
* {#if win.visible}
|
|
174
|
+
* <div class="panel">
|
|
175
|
+
* <button onclick={() => win.close()}>Close</button>
|
|
176
|
+
* </div>
|
|
177
|
+
* {/if}
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export function useNuiWindow(windowName, options = {}) {
|
|
181
|
+
const client = options.client ?? useNuiClient();
|
|
182
|
+
const controller = new NuiWindowController(windowName, options, client);
|
|
183
|
+
if (options.autoDestroy !== false) {
|
|
184
|
+
try {
|
|
185
|
+
onDestroy(controller.destroy);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (options.autoDestroy === true) {
|
|
189
|
+
controller.destroy();
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return controller;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=window.svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window.svelte.js","sourceRoot":"","sources":["../../src/runes/window.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,sCAAe,CAAA;IACf,sCAAe,CAAA;IACf,0CAAmB,CAAA;AACrB,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,wCAAe,CAAA;IACf,wCAAe,CAAA;AACjB,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC;AAuED,SAAS,YAAY,CACnB,SAAiB,EACjB,QAAgD,EAChD,GAAG,IAAW;IAEd,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEtB,IAAI,CAAC;QACH,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,kBAAkB;aACpB,MAAM,CACL,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,C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;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAkB,EAClB,OAAO,GAAqB,EAAE;IAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;IAChD,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,OAAO,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;gBACjC,UAAU,CAAC,OAAO,EAAE,CAAC;gBACrB,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,WAAW,EACX,QAAQ,EACR,eAAe,EACf,WAAW,EACX,eAAe,EAChB,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,yCAAyC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type augmentation for FiveM NUI events.
|
|
3
|
+
* Extend this interface in your project to get type safety.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // In separate .d.ts file in your project:
|
|
8
|
+
* declare module '@fivem-nui/core' {
|
|
9
|
+
* interface NuiEventMap {
|
|
10
|
+
* 'player:health': { payload: { health: number } };
|
|
11
|
+
* 'inventory:get': { request: { id: string }; response: Item };
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { NuiEventMap as CoreNuiEventMap, NuiEventPayload } from '@fivem-nui/core';
|
|
17
|
+
/**
|
|
18
|
+
* Extended NuiEventMap that can be augmented by consumers.
|
|
19
|
+
*/
|
|
20
|
+
export interface NuiEventMap extends CoreNuiEventMap {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Available event keys from the extended event map.
|
|
24
|
+
*/
|
|
25
|
+
export type EventKey<T extends NuiEventMap = NuiEventMap> = keyof T;
|
|
26
|
+
/**
|
|
27
|
+
* Payload type for a specific event.
|
|
28
|
+
*/
|
|
29
|
+
export type PayloadForEvent<E extends EventKey> = NuiEventPayload<E>;
|
|
30
|
+
/**
|
|
31
|
+
* Re-export core types for convenience
|
|
32
|
+
*/
|
|
33
|
+
export type { NuiEventKey, NuiEventPayload } from '@fivem-nui/core';
|
|
34
|
+
//# sourceMappingURL=nui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nui.d.ts","sourceRoot":"","sources":["../../src/types/nui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAe,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpG;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,eAAe;CAAI;AAExD;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,MAAM,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;AAErE;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type augmentation for FiveM NUI events.
|
|
3
|
+
* Extend this interface in your project to get type safety.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // In separate .d.ts file in your project:
|
|
8
|
+
* declare module '@fivem-nui/core' {
|
|
9
|
+
* interface NuiEventMap {
|
|
10
|
+
* 'player:health': { payload: { health: number } };
|
|
11
|
+
* 'inventory:get': { request: { id: string }; response: Item };
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=nui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nui.js","sourceRoot":"","sources":["../../src/types/nui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the current page is running inside FiveM's Chromium Embedded Framework (CEF).
|
|
3
|
+
* In FiveM CEF, `window.GetParentResourceName` is injected as a native global function.
|
|
4
|
+
*
|
|
5
|
+
* @returns `true` if executing within FiveM CEF, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isNui(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Returns true when running in a standard browser (Vite dev server, standalone preview), outside FiveM.
|
|
10
|
+
*
|
|
11
|
+
* @returns `true` if running in a standard browser outside FiveM, `false` if inside CEF.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isBrowser(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Safely resolves the parent resource name if running in FiveM CEF, or returns fallback in browser.
|
|
16
|
+
*
|
|
17
|
+
* @param fallback - Resource name to return if not running in FiveM CEF or if resolution fails.
|
|
18
|
+
* @returns The FiveM resource name or the provided fallback.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getResourceName(fallback?: string): string;
|
|
21
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAqB,GAAG,MAAM,CAUrE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the current page is running inside FiveM's Chromium Embedded Framework (CEF).
|
|
3
|
+
* In FiveM CEF, `window.GetParentResourceName` is injected as a native global function.
|
|
4
|
+
*
|
|
5
|
+
* @returns `true` if executing within FiveM CEF, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isNui() {
|
|
8
|
+
return typeof globalThis.GetParentResourceName === 'function';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns true when running in a standard browser (Vite dev server, standalone preview), outside FiveM.
|
|
12
|
+
*
|
|
13
|
+
* @returns `true` if running in a standard browser outside FiveM, `false` if inside CEF.
|
|
14
|
+
*/
|
|
15
|
+
export function isBrowser() {
|
|
16
|
+
return !isNui();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Safely resolves the parent resource name if running in FiveM CEF, or returns fallback in browser.
|
|
20
|
+
*
|
|
21
|
+
* @param fallback - Resource name to return if not running in FiveM CEF or if resolution fails.
|
|
22
|
+
* @returns The FiveM resource name or the provided fallback.
|
|
23
|
+
*/
|
|
24
|
+
export function getResourceName(fallback = 'unknown_resource') {
|
|
25
|
+
const g = globalThis;
|
|
26
|
+
if (typeof g.GetParentResourceName === 'function') {
|
|
27
|
+
try {
|
|
28
|
+
return g.GetParentResourceName();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,KAAK;IACnB,OAAO,OAAQ,UAAkD,CAAC,qBAAqB,KAAK,UAAU,CAAC;AACzG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,QAAQ,GAAG,kBAAkB;IAC3D,MAAM,CAAC,GAAG,UAAsD,CAAC;IACjE,IAAI,OAAO,CAAC,CAAC,qBAAqB,KAAK,UAAU,EAAE,CAAC;QAClD,IAAI,CAAC;YACH,OAAO,CAAC,CAAC,qBAAqB,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether an error represents an aborted asynchronous operation.
|
|
3
|
+
* Matches standard DOMException AbortError, Fetch AbortError, or custom NuiRequestError with code 'ABORTED'.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isAbortError(err: unknown): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an AbortError in an environment-agnostic way.
|
|
8
|
+
* Uses global DOMException if available; falls back to Error with name 'AbortError' and code 'ABORTED'.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createAbortError(message?: string): Error | DOMException;
|
|
11
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAWlD;AAGD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAA+B,GAAG,KAAK,GAAG,YAAY,CAQ7F"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether an error represents an aborted asynchronous operation.
|
|
3
|
+
* Matches standard DOMException AbortError, Fetch AbortError, or custom NuiRequestError with code 'ABORTED'.
|
|
4
|
+
*/
|
|
5
|
+
export function isAbortError(err) {
|
|
6
|
+
if (typeof err !== 'object' || err === null) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const candidate = err;
|
|
11
|
+
return candidate.name === 'AbortError' || candidate.code === 'ABORTED';
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates an AbortError in an environment-agnostic way.
|
|
19
|
+
* Uses global DOMException if available; falls back to Error with name 'AbortError' and code 'ABORTED'.
|
|
20
|
+
*/
|
|
21
|
+
export function createAbortError(message = 'The operation was aborted.') {
|
|
22
|
+
if (typeof DOMException !== 'undefined') {
|
|
23
|
+
return new DOMException(message, 'AbortError');
|
|
24
|
+
}
|
|
25
|
+
const err = new Error(message);
|
|
26
|
+
err.name = 'AbortError';
|
|
27
|
+
err.code = 'ABORTED';
|
|
28
|
+
return err;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,GAAyC,CAAC;QAC5D,OAAO,SAAS,CAAC,IAAI,KAAK,YAAY,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAGD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAO,GAAG,4BAA4B;IACrE,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;QACxC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,GAAG,CAAC,IAAI,GAAG,YAAY,CAAC;IACvB,GAAyB,CAAC,IAAI,GAAG,SAAS,CAAC;IAC5C,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard modifier keys.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum NuiKeyboardModifier {
|
|
5
|
+
Ctrl = "ctrl",
|
|
6
|
+
Alt = "alt",
|
|
7
|
+
Shift = "shift",
|
|
8
|
+
Meta = "meta"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Standard special key names commonly used in FiveM NUI shortcuts.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum NuiSpecialKey {
|
|
14
|
+
Escape = "Escape",
|
|
15
|
+
Enter = "Enter",
|
|
16
|
+
Tab = "Tab",
|
|
17
|
+
Space = " ",
|
|
18
|
+
Backspace = "Backspace",
|
|
19
|
+
ArrowUp = "ArrowUp",
|
|
20
|
+
ArrowDown = "ArrowDown",
|
|
21
|
+
ArrowLeft = "ArrowLeft",
|
|
22
|
+
ArrowRight = "ArrowRight"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration options for keyboard event handlers and shortcuts.
|
|
26
|
+
*/
|
|
27
|
+
export interface KeyOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Listen during capture phase.
|
|
30
|
+
* @defaultValue false
|
|
31
|
+
*/
|
|
32
|
+
capture?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Automatically call `event.preventDefault()`.
|
|
35
|
+
* @defaultValue false
|
|
36
|
+
*/
|
|
37
|
+
preventDefault?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Automatically call `event.stopPropagation()`.
|
|
40
|
+
* @defaultValue false
|
|
41
|
+
*/
|
|
42
|
+
stopPropagation?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the key shortcut is enabled.
|
|
45
|
+
* Accepts a static boolean or a reactive getter `() => boolean`.
|
|
46
|
+
* @defaultValue true
|
|
47
|
+
*/
|
|
48
|
+
enabled?: boolean | (() => boolean);
|
|
49
|
+
/**
|
|
50
|
+
* If true, suppresses shortcut execution when the active element is an input,
|
|
51
|
+
* textarea, select, or contenteditable.
|
|
52
|
+
* Crucial in FiveM NUI panels to prevent game hotkeys firing while typing messages/searches.
|
|
53
|
+
* @defaultValue false
|
|
54
|
+
*/
|
|
55
|
+
ignoreInputs?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Ignore repeating keydown events triggered while holding a key down.
|
|
58
|
+
* @defaultValue false
|
|
59
|
+
*/
|
|
60
|
+
ignoreRepeat?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Require Ctrl key to be pressed (or Cmd on Mac).
|
|
63
|
+
*/
|
|
64
|
+
ctrl?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Require Alt key to be pressed.
|
|
67
|
+
*/
|
|
68
|
+
alt?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Require Shift key to be pressed.
|
|
71
|
+
*/
|
|
72
|
+
shift?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Require Meta (Windows / Cmd) key to be pressed.
|
|
75
|
+
*/
|
|
76
|
+
meta?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Component lifecycle registration strategy:
|
|
79
|
+
* - `true`: Strictly requires component initialization lifecycle; registers `onDestroy`.
|
|
80
|
+
* If called outside a component, unsubscribes immediately to prevent memory leaks and throws.
|
|
81
|
+
* - `false`: Disables automatic lifecycle cleanup. The caller must invoke the returned cleanup function manually.
|
|
82
|
+
* - `undefined` (default): Attempts to register `onDestroy` within a component lifecycle;
|
|
83
|
+
* falls back gracefully to manual cleanup if called outside a component.
|
|
84
|
+
* @defaultValue undefined
|
|
85
|
+
*/
|
|
86
|
+
autoDestroy?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Registers a keyboard shortcut with automatic lifecycle management.
|
|
90
|
+
*
|
|
91
|
+
* Designed for FiveM NUI with support for:
|
|
92
|
+
* - `ignoreInputs`: prevents hotkeys from firing while typing in input fields.
|
|
93
|
+
* - Modifier keys (Ctrl, Alt, Shift, Meta).
|
|
94
|
+
* - Automatic cleanup via `onDestroy` and `AbortController`.
|
|
95
|
+
*
|
|
96
|
+
* @param keys - Key or array of keys (case-insensitive) to listen for.
|
|
97
|
+
* @param handler - Callback function invoked when matching keydown occurs.
|
|
98
|
+
* @param options - Optional shortcut configuration including modifiers and lifecycle strategy.
|
|
99
|
+
* @returns Cleanup function to remove event listeners.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```svelte
|
|
103
|
+
* <script>
|
|
104
|
+
* import { useNuiKey } from '@fivem-nui/svelte';
|
|
105
|
+
* useNuiKey('e', () => interact(), { ignoreInputs: true });
|
|
106
|
+
* </script>
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function useNuiKey(keys: string | string[], handler: (event: KeyboardEvent) => void, options?: KeyOptions): () => void;
|
|
110
|
+
/**
|
|
111
|
+
* Listens for the `Escape` key to close or dismiss NUI panels.
|
|
112
|
+
* In FiveM, ESC is the universal standard for closing NUI windows.
|
|
113
|
+
*
|
|
114
|
+
* @param onEscape - Callback function invoked when the Escape key is pressed.
|
|
115
|
+
* @param options - Optional configuration overriding default key options (`preventDefault` defaults to `true`).
|
|
116
|
+
* @returns Cleanup function to remove the Escape listener.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```svelte
|
|
120
|
+
* <script>
|
|
121
|
+
* import { useNuiEscape, nui } from '@fivem-nui/svelte';
|
|
122
|
+
* useNuiEscape(() => nui.notify('close'));
|
|
123
|
+
* </script>
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function useNuiEscape(onEscape: (event: KeyboardEvent) => void, options?: KeyOptions): () => void;
|
|
127
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/utils/keyboard.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,KAAK,MAAM;IACX,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,UAAU,eAAe;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC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