lenix 1.7.21 → 1.7.22

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/client/_init.ts CHANGED
@@ -1,7 +1,10 @@
1
- import type { _InternalRequests } from '../shared/types.ts'
1
+ import type { Request } from '../shared/types.ts'
2
2
  import { onNui } from './nui.ts'
3
3
 
4
- onNui<_InternalRequests['focus']>('__nuiFocus', ({
4
+ onNui<Request<true, '__nuiFocus', {
5
+ keyboard: boolean,
6
+ cursor: boolean
7
+ }>>('__nuiFocus', ({
5
8
  keyboard,
6
9
  cursor
7
10
  }) => {
package/client/client.ts CHANGED
@@ -1,8 +1,7 @@
1
+ import { JsonValue } from '@lenix/lenix'
1
2
  import { repeat } from '../shared/repeat.ts'
2
3
  import type { Vec3, Vec4 } from '../shared/types.ts'
3
4
 
4
- type JsonPrimitive = string | number | boolean | null
5
- type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
6
5
 
7
6
  export const client = {
8
7
  entity: {
@@ -1,11 +1,12 @@
1
+ import { JsonValue } from '@lenix/lenix'
1
2
  import type { Request } from '../shared/types.ts'
2
3
 
3
4
  declare function GetParentResourceName(): string
4
5
 
5
6
  /**
6
- * Sends a typed request from the NUI browser to the game client.
7
+ * Fetchs a typed request from the NUI browser to the game client.
7
8
  */
8
- export const triggerNui = async <T extends Request<unknown, string, object>>(
9
+ export const fetchNui = async <T extends Request<JsonValue, string, object>>(
9
10
  id: T[1],
10
11
  data: T[2]
11
12
  ): Promise<T[0]> => {
@@ -19,6 +20,6 @@ export const triggerNui = async <T extends Request<unknown, string, object>>(
19
20
  })
20
21
  return await response.json()
21
22
  } catch (e) {
22
- throw new Error(`Error occured while emiting an nui<${id}>.\n${e}`)
23
+ throw `Error occured while emiting an nui<${id}>.\n${e}`
23
24
  }
24
25
  }
package/nui/focus.ts CHANGED
@@ -1,10 +1,27 @@
1
- import type { _InternalRequests } from '../shared/types.ts'
2
- import { triggerNui } from './trigger.ts'
1
+ import { Request } from '../shared/types.ts'
2
+ import { fetchNui } from './fetch.ts'
3
3
 
4
4
  /**
5
5
  * Requests keyboard and cursor focus for the NUI browser.
6
6
  */
7
- export const focus = (
8
- keyboard = true,
9
- cursor = true
10
- ): Promise<true> => triggerNui<_InternalRequests['focus']>('__nuiFocus', { keyboard, cursor })
7
+ export const focus = (exclude?: 'keyboard' | 'cursor'): Promise<true> => {
8
+ return fetchNui<Request<true, '__nuiFocus', {
9
+ keyboard: boolean,
10
+ cursor: boolean
11
+ }>>('__nuiFocus', { keyboard: exclude === 'keyboard' ? false : true, cursor: exclude === 'cursor' ? false : true })
12
+ }
13
+
14
+ export const unFocus = (
15
+ key: KeyboardEvent['key'],
16
+ onEvent: () => void
17
+ ) => {
18
+
19
+ const handler = (e: KeyboardEvent) => {
20
+ if (e.key !== key) return
21
+
22
+ onEvent()
23
+ }
24
+
25
+ window.addEventListener('keydown', handler)
26
+ return () => window.removeEventListener('keydown', handler)
27
+ }
package/nui/index.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  */
7
7
 
8
8
  export * from './on.ts'
9
- export * from './trigger.ts'
9
+ export * from './fetch.ts'
10
10
  export * from './focus.ts'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lenix",
3
- "version": "1.7.21",
3
+ "version": "1.7.22",
4
4
  "description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
5
5
  "author": "Lenix",
6
6
  "license": "MIT",
@@ -47,6 +47,6 @@
47
47
  "typescript": "^5"
48
48
  },
49
49
  "dependencies": {
50
- "@lenix/lenix": "npm:@jsr/lenix__lenix"
50
+ "@lenix/lenix": "npm:@jsr/lenix__lenix@1.8.16"
51
51
  }
52
52
  }
package/shared/index.ts CHANGED
@@ -7,3 +7,4 @@
7
7
  export * from './types.ts'
8
8
  export * from './repeat.ts'
9
9
  export * from './palette.ts'
10
+ export * from './timer.ts'
package/shared/timer.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  /**
2
2
  * Starts a client timer using FiveM game time.
3
3
  */
4
- export const useTimer = (
4
+ export const useTimer = ({
5
+ duration,
6
+ updateInterval,
7
+ onTick,
8
+ onEnd
9
+ }: {
5
10
  duration: number,
6
11
  updateInterval: number,
7
12
  onTick: (timeLeft: number) => void,
8
13
  onEnd: () => void
9
- ): () => void => {
14
+ }): () => void => {
10
15
  const start = GetGameTimer()
11
16
 
12
17
  const interval = setInterval(() => {
package/shared/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { JsonValue } from "@lenix/lenix"
2
+
1
3
  /**
2
4
  * Three-dimensional coordinates plus heading.
3
5
  */
@@ -17,19 +19,8 @@ export type Event<Id extends string, Params extends unknown[] = never> = [Id, Pa
17
19
  * Typed request tuple containing a response type, request id, and object payload.
18
20
  */
19
21
  export type Request<
20
- Response,
22
+ Response extends JsonValue,
21
23
  Id extends string,
22
24
  Params extends object = { [key: string]: unknown }
23
25
  > = Params extends readonly unknown[] ? never
24
26
  : [Response, Id, Params]
25
-
26
-
27
- /**
28
- * Internal NUI requests used by Lenix helpers. DO NOT USE
29
- */
30
- export interface _InternalRequests {
31
- focus: Request<true, '__nuiFocus', {
32
- keyboard: boolean,
33
- cursor: boolean
34
- }>
35
- }