@solidrt/core 0.0.1-exp.9 → 0.0.2
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 +5 -1
- package/src/focus.ts +21 -0
- package/src/index.ts +2 -1
- package/src/types.d.ts +11 -4
- package/src/window.ts +61 -6
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidrt/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"author": "Antoine van Wel",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "src/index.ts",
|
|
7
8
|
"exports": {
|
|
@@ -17,6 +18,9 @@
|
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"colord": "^2.9.3"
|
|
19
20
|
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@solidrt/flux-types": "0.0.2"
|
|
23
|
+
},
|
|
20
24
|
"peerDependencies": {
|
|
21
25
|
"@solidjs/signals": "2.0.0-beta.13",
|
|
22
26
|
"@solidjs/universal": "2.0.0-beta.13"
|
package/src/focus.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getEventHandler } from "./events"
|
|
2
|
+
|
|
3
|
+
// Currently-focused node id. Reset to null automatically across engine
|
|
4
|
+
// reloads because the JS environment is rebuilt from scratch.
|
|
5
|
+
let focusedNodeId: number | null = null
|
|
6
|
+
|
|
7
|
+
export function setFocus(nodeId: number | null): void {
|
|
8
|
+
if (nodeId === focusedNodeId) return
|
|
9
|
+
let oldId = focusedNodeId
|
|
10
|
+
focusedNodeId = nodeId
|
|
11
|
+
if (oldId != null) {
|
|
12
|
+
getEventHandler(oldId, "onBlur")?.()
|
|
13
|
+
}
|
|
14
|
+
if (nodeId != null) {
|
|
15
|
+
getEventHandler(nodeId, "onFocus")?.()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getFocusedNodeId(): number | null {
|
|
20
|
+
return focusedNodeId
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
/// <reference types="@solidrt/flux-types" />
|
|
2
|
+
|
|
1
3
|
import type { Accessor, JSX as SolidJSX } from "@solidjs/signals"
|
|
2
4
|
|
|
3
5
|
declare global {
|
|
4
|
-
let Flux: {
|
|
5
|
-
on(event: string, callback: (data: any) => void): () => void
|
|
6
|
-
}
|
|
7
6
|
|
|
8
7
|
let ffi: {
|
|
9
8
|
createRoot(id: number): void
|
|
@@ -22,6 +21,7 @@ interface FlexboxProps {
|
|
|
22
21
|
gap?: number
|
|
23
22
|
rowGap?: number
|
|
24
23
|
columnGap?: number
|
|
24
|
+
flex?: number | "none" | "auto" | (string & {})
|
|
25
25
|
flexGrow?: number
|
|
26
26
|
flexShrink?: number
|
|
27
27
|
flexBasis?: number
|
|
@@ -77,6 +77,8 @@ export interface LayoutProps extends FlexboxProps, GridProps {
|
|
|
77
77
|
marginLeft?: Dimension
|
|
78
78
|
|
|
79
79
|
overflow?: "visible" | "clip" | "hidden" | "scroll"
|
|
80
|
+
overflowX?: "visible" | "clip" | "hidden" | "scroll"
|
|
81
|
+
overflowY?: "visible" | "clip" | "hidden" | "scroll"
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
import type { LCH } from "./color"
|
|
@@ -97,6 +99,8 @@ export interface TransformProps {
|
|
|
97
99
|
scale?: OA<number>
|
|
98
100
|
x?: OA<number>
|
|
99
101
|
y?: OA<number>
|
|
102
|
+
cx?: OA<number>
|
|
103
|
+
cy?: OA<number>
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
export interface PointerProps {
|
|
@@ -124,6 +128,7 @@ interface Position {
|
|
|
124
128
|
export interface WindowProps extends LayoutProps {
|
|
125
129
|
children?: Children
|
|
126
130
|
title?: string
|
|
131
|
+
fullscreen?: boolean
|
|
127
132
|
vsync?: boolean
|
|
128
133
|
fps?: boolean
|
|
129
134
|
}
|
|
@@ -159,9 +164,11 @@ export interface PathProps extends Position, PaintProps, PointerProps {
|
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
export interface TextProps extends PaintProps {
|
|
162
|
-
children
|
|
167
|
+
children?: Children
|
|
168
|
+
fontFamily?: "sans" | "mono" | (string & {})
|
|
163
169
|
fontSize?: number
|
|
164
170
|
fontStyle?: "normal" | "italic"
|
|
171
|
+
fontWeight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
|
165
172
|
textAlign?: "left" | "right" | "center" | "justify"
|
|
166
173
|
maxLines?: number
|
|
167
174
|
}
|
package/src/window.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { onCleanup, onSettled } from "@solidjs/signals"
|
|
2
2
|
import { getEventHandler } from "./events"
|
|
3
|
+
import { getFocusedNodeId } from "./focus"
|
|
3
4
|
|
|
4
5
|
// ------ Animation frames ----------------
|
|
5
6
|
|
|
@@ -49,13 +50,30 @@ export function onResize(fn: (data: ResizeEvent) => void) {
|
|
|
49
50
|
return unsubscribe
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
export function onWindowFocus(fn: () => void) {
|
|
54
|
+
let unsubscribe = Flux.on("windowFocus", fn)
|
|
55
|
+
onCleanup(unsubscribe)
|
|
56
|
+
return unsubscribe
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function onWindowBlur(fn: () => void) {
|
|
60
|
+
let unsubscribe = Flux.on("windowBlur", fn)
|
|
61
|
+
onCleanup(unsubscribe)
|
|
62
|
+
return unsubscribe
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
// ------ Window ----------------
|
|
53
66
|
|
|
54
67
|
export function attachWindow(_nodeId: number) {
|
|
55
68
|
let unsubscribe: () => void = null!
|
|
56
69
|
let unsubDown: () => void = null!
|
|
70
|
+
let unsubUp: () => void = null!
|
|
71
|
+
let unsubMove: () => void = null!
|
|
57
72
|
let unsubEnter: () => void = null!
|
|
58
73
|
let unsubLeave: () => void = null!
|
|
74
|
+
let unsubWheel: () => void = null!
|
|
75
|
+
let unsubKeyDown: () => void = null!
|
|
76
|
+
let unsubKeyUp: () => void = null!
|
|
59
77
|
|
|
60
78
|
onSettled(() => {
|
|
61
79
|
unsubscribe = Flux.on("render", ({ time, frame }: { time: number, frame: number }) => {
|
|
@@ -70,21 +88,53 @@ export function attachWindow(_nodeId: number) {
|
|
|
70
88
|
draw()
|
|
71
89
|
})
|
|
72
90
|
|
|
73
|
-
unsubDown = Flux.on("pointerDown", ({ targets,
|
|
91
|
+
unsubDown = Flux.on("pointerDown", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
92
|
+
for (let nodeId of targets) {
|
|
93
|
+
getEventHandler(nodeId, "onPointerDown")?.(e)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
unsubUp = Flux.on("pointerUp", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
98
|
+
for (let nodeId of targets) {
|
|
99
|
+
getEventHandler(nodeId, "onPointerUp")?.(e)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
unsubMove = Flux.on("pointerMove", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
104
|
+
for (let nodeId of targets) {
|
|
105
|
+
getEventHandler(nodeId, "onPointerMove")?.(e)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
unsubEnter = Flux.on("pointerEnter", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
74
110
|
for (let nodeId of targets) {
|
|
75
|
-
getEventHandler(nodeId, "
|
|
111
|
+
getEventHandler(nodeId, "onPointerEnter")?.(e)
|
|
76
112
|
}
|
|
77
113
|
})
|
|
78
114
|
|
|
79
|
-
|
|
115
|
+
unsubLeave = Flux.on("pointerLeave", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
80
116
|
for (let nodeId of targets) {
|
|
81
|
-
getEventHandler(nodeId, "
|
|
117
|
+
getEventHandler(nodeId, "onPointerLeave")?.(e)
|
|
82
118
|
}
|
|
83
119
|
})
|
|
84
120
|
|
|
85
|
-
|
|
121
|
+
unsubWheel = Flux.on("wheel", ({ targets, ...e }: { targets: number[], [k: string]: any }) => {
|
|
86
122
|
for (let nodeId of targets) {
|
|
87
|
-
getEventHandler(nodeId, "
|
|
123
|
+
getEventHandler(nodeId, "onWheel")?.(e)
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
unsubKeyDown = Flux.on("keydown", (e: any) => {
|
|
128
|
+
let id = getFocusedNodeId()
|
|
129
|
+
if (id != null) {
|
|
130
|
+
getEventHandler(id, "onKeyDown")?.(e)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
unsubKeyUp = Flux.on("keyup", (e: any) => {
|
|
135
|
+
let id = getFocusedNodeId()
|
|
136
|
+
if (id != null) {
|
|
137
|
+
getEventHandler(id, "onKeyUp")?.(e)
|
|
88
138
|
}
|
|
89
139
|
})
|
|
90
140
|
|
|
@@ -95,7 +145,12 @@ export function attachWindow(_nodeId: number) {
|
|
|
95
145
|
onCleanup(() => {
|
|
96
146
|
if (unsubscribe) unsubscribe()
|
|
97
147
|
if (unsubDown) unsubDown()
|
|
148
|
+
if (unsubUp) unsubUp()
|
|
149
|
+
if (unsubMove) unsubMove()
|
|
98
150
|
if (unsubEnter) unsubEnter()
|
|
99
151
|
if (unsubLeave) unsubLeave()
|
|
152
|
+
if (unsubWheel) unsubWheel()
|
|
153
|
+
if (unsubKeyDown) unsubKeyDown()
|
|
154
|
+
if (unsubKeyUp) unsubKeyUp()
|
|
100
155
|
})
|
|
101
156
|
}
|