onejs-core 2.0.4 → 2.0.6
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/definitions/globals.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
28
|
+
subscribe<T, K extends EventNames<T>>(
|
|
24
29
|
eventSource: T,
|
|
25
30
|
eventName: K,
|
|
26
|
-
handler:
|
|
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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const postcss = require('postcss')
|
|
2
|
+
const selectorParser = require('postcss-selector-parser')
|
|
3
|
+
|
|
4
|
+
module.exports = postcss.plugin('postcss-unwrap-is', () => {
|
|
5
|
+
return (root) => {
|
|
6
|
+
root.walkRules(rule => {
|
|
7
|
+
rule.selector = selectorParser(selectors => {
|
|
8
|
+
selectors.walkPseudos(pseudo => {
|
|
9
|
+
if (pseudo.value === ':is') {
|
|
10
|
+
// replace the entire :is(...) with its contents
|
|
11
|
+
pseudo.replaceWith(...pseudo.nodes)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
}).processSync(rule.selector)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
})
|