@solidrt/core 0.0.1-exp.4 → 0.0.1-exp.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.
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/types.d.ts +4 -0
- package/src/window.ts +34 -13
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/types.d.ts
CHANGED
package/src/window.ts
CHANGED
|
@@ -5,26 +5,47 @@ import { onCleanup, onSettled } from "@solidjs/signals"
|
|
|
5
5
|
let nextFrameId = 1
|
|
6
6
|
let animationFrames = new Map<number, Function>()
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export let cancelAnimationFrame = (id: number) => {
|
|
15
|
-
animationFrames.delete(id)
|
|
16
|
-
}
|
|
17
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Calls `fn` on every rendered frame. Returns a cleanup function to stop rendering.
|
|
10
|
+
* When called within a reactive scope (e.g. a component or createEffect), cleanup is also automatic.
|
|
11
|
+
*/
|
|
18
12
|
export function onRender(fn: (tick: number) => void) {
|
|
19
13
|
let frameId: number = null!
|
|
20
14
|
|
|
21
15
|
let extendedFn = (tick: number) => {
|
|
22
16
|
fn(tick)
|
|
23
|
-
frameId =
|
|
17
|
+
frameId = nextFrameId++
|
|
18
|
+
animationFrames.set(frameId, extendedFn)
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
frameId =
|
|
27
|
-
|
|
21
|
+
frameId = nextFrameId++
|
|
22
|
+
animationFrames.set(frameId, extendedFn)
|
|
23
|
+
|
|
24
|
+
let cleanup = () => animationFrames.delete(frameId)
|
|
25
|
+
onCleanup(cleanup)
|
|
26
|
+
return cleanup
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ------ Resize ----------------
|
|
30
|
+
|
|
31
|
+
interface SafeArea {
|
|
32
|
+
top: number
|
|
33
|
+
left: number
|
|
34
|
+
right: number
|
|
35
|
+
bottom: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ResizeEvent {
|
|
39
|
+
width: number
|
|
40
|
+
height: number
|
|
41
|
+
safeArea: SafeArea
|
|
42
|
+
displayScale: number
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function onResize(fn: (data: ResizeEvent) => void) {
|
|
46
|
+
let unsubscribe = Flux.on("resize", fn)
|
|
47
|
+
onCleanup(unsubscribe)
|
|
48
|
+
return unsubscribe
|
|
28
49
|
}
|
|
29
50
|
|
|
30
51
|
// ------ Window ----------------
|