onejs-core 2.0.4 → 2.0.5

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.
@@ -1,13 +1,18 @@
1
- declare namespace OneJS {
2
- class Event<F extends Function> {
3
- // Must have at least an unique member, because an empty class behaves like `any`
4
- #Invoke(...args: any): any
5
- }
6
-
7
- type EventKeys<T> = { [k in keyof T]-?: T[k] extends Event<any> ? k : never }[keyof T]
8
-
9
- type EventGenericType<T> = T extends Event<infer F> ? F : never
10
- }
1
+ type Instance<T> = T extends new (...a: any) => infer I ? I : never
2
+
3
+ type EventNames<T> = {
4
+ [K in keyof T]:
5
+ K extends `add_${infer E}`
6
+ ? `remove_${E}` extends keyof T ? E : never
7
+ : never
8
+ }[keyof T]
9
+
10
+ type Handler<T, E extends string> =
11
+ `add_${E}` extends keyof T
12
+ ? T[`add_${E}`] extends (arg: infer A) => any
13
+ ? A
14
+ : never
15
+ : never
11
16
 
12
17
  declare const onejs: {
13
18
  add_onReload(handler: () => void): void
@@ -20,10 +25,20 @@ declare const onejs: {
20
25
  // objects: Record<string, any>
21
26
  // }
22
27
 
23
- subscribe<T, K extends OneJS.EventKeys<T>>(
28
+ subscribe<T, K extends EventNames<T>>(
24
29
  eventSource: T,
25
30
  eventName: K,
26
- handler: OneJS.EventGenericType<T[K]>
31
+ handler: Function
32
+ ): CS.System.Action
33
+
34
+ subscribe<
35
+ C extends new (...a: any) => any,
36
+ I extends Instance<C>,
37
+ E extends EventNames<I>
38
+ >(
39
+ eventSource: C,
40
+ eventName: E,
41
+ handler: Function
27
42
  ): CS.System.Action
28
43
 
29
44
  subscribe(eventName: string, handler: () => void): CS.System.Action
@@ -0,0 +1,4 @@
1
+ export type Breakpoint = "base" | "xs" | "sm" | "md" | "lg" | "xl";
2
+ export type Responsive = number | Partial<Record<Breakpoint, number>>;
3
+ /** Pick the right value for the current width. */
4
+ export declare function resolveResponsive<T>(val: Responsive, w?: number): number;
@@ -0,0 +1,23 @@
1
+ const BP = {
2
+ xs: 480,
3
+ sm: 640,
4
+ md: 768,
5
+ lg: 1024,
6
+ xl: 1280,
7
+ };
8
+ /** Current viewport width (UI Toolkit) */
9
+ const getWidth = () => document.body.ve.resolvedStyle.width;
10
+ /** Pick the right value for the current width. */
11
+ export function resolveResponsive(val, w = getWidth()) {
12
+ if (typeof val !== "object")
13
+ return val;
14
+ let picked = val.base;
15
+ for (const [bp, px] of Object.entries(BP)) {
16
+ if (w >= px && val[bp] !== undefined)
17
+ picked = val[bp];
18
+ }
19
+ setTimeout(() => {
20
+ console.log(CS.UnityEngine.Screen.dpi);
21
+ }, 1);
22
+ return picked;
23
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onejs-core",
3
3
  "description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
4
- "version": "2.0.4",
4
+ "version": "2.0.5",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "bin": {
@@ -30,6 +30,9 @@ exports.plugins = [
30
30
  ".wrap": {
31
31
  "white-space": "normal",
32
32
  },
33
+ ".font-bold": {
34
+ "-unity-font-style": "bold",
35
+ },
33
36
  ".bold": {
34
37
  "-unity-font-style": "bold",
35
38
  },
package/tsconfig.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "jsxFactory": "h",
10
10
  "jsxFragmentFactory": "Fragment",
11
11
  "skipLibCheck": false,
12
+ "strictNullChecks": true,
12
13
  "forceConsistentCasingInFileNames": true,
13
14
  "declaration": true,
14
15
  "typeRoots": [ ],