canvasengine 2.0.0-beta.44 → 2.0.0-beta.45
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/dist/{DebugRenderer-P5sZ-0Tq.js → DebugRenderer-CSxse9YI.js} +2 -2
- package/dist/{DebugRenderer-P5sZ-0Tq.js.map → DebugRenderer-CSxse9YI.js.map} +1 -1
- package/dist/engine/reactive.d.ts +10 -0
- package/dist/engine/reactive.d.ts.map +1 -1
- package/dist/engine/signal.d.ts +19 -19
- package/dist/engine/signal.d.ts.map +1 -1
- package/dist/{index-VPoz4ufu.js → index-DH2ZMhYm.js} +1946 -1922
- package/dist/index-DH2ZMhYm.js.map +1 -0
- package/dist/index.global.js +3 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -44
- package/package.json +1 -1
- package/src/engine/reactive.ts +53 -15
- package/src/engine/signal.ts +80 -23
- package/dist/index-VPoz4ufu.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { h as a } from "./index-
|
|
2
|
-
import { A as
|
|
1
|
+
import { h as a } from "./index-DH2ZMhYm.js";
|
|
2
|
+
import { A as o, a4 as r, a5 as n, B as c, M as l, H as u, C as p, k as m, a2 as S, a3 as d, aw as g, m as C, D as b, av as h, at as k, N as w, o as D, a7 as E, a as j, G as F, L as T, j as f, I as v, a6 as y, J as O, K as x, U as M, a1 as A, O as P, X as V, au as B, R as G, W as H, S as q, n as I, l as J, Y as N, Q as R, _ as z, $ as K, T as U, P as L, g as Q, Z as W, a0 as X, V as Y, as as Z, ar as _, ap as $, ab as aa, p as sa, ag as ea, ae as ta, ah as ia, q as oa, f as ra, al as na, aq as ca, s as la, t as ua, a8 as pa, ad as ma, v as Sa, i as da, a9 as ga, w as Ca, am as ba, x as ha, af as ka, aj as wa, ai as Da, ao as Ea, r as ja, aa as Fa, y as Ta, ak as fa, an as va, z as ya, b as Oa, e as xa, c as Ma, d as Aa, u as Pa, ac as Va } from "./index-DH2ZMhYm.js";
|
|
3
3
|
const e = a.Howler;
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
o as ArraySubject,
|
|
6
|
+
r as Button,
|
|
7
7
|
n as ButtonState,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
c as Canvas,
|
|
9
|
+
l as Circle,
|
|
10
10
|
u as Container,
|
|
11
11
|
p as ControlsBase,
|
|
12
12
|
m as ControlsDirective,
|
|
13
13
|
S as DOMContainer,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
d as DOMElement,
|
|
15
|
+
g as DisplayObject,
|
|
16
16
|
C as Drag,
|
|
17
17
|
b as Drop,
|
|
18
18
|
h as EVENTS,
|
|
19
19
|
k as Easing,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
w as Ellipse,
|
|
21
|
+
D as Flash,
|
|
22
|
+
E as FocusContainer,
|
|
23
|
+
j as FocusManager,
|
|
24
|
+
F as GamepadControls,
|
|
25
|
+
T as Graphics,
|
|
26
|
+
f as Howl,
|
|
27
27
|
e as Howler,
|
|
28
28
|
v as Input,
|
|
29
29
|
y as Joystick,
|
|
@@ -52,38 +52,40 @@ export {
|
|
|
52
52
|
Z as animatedSequence,
|
|
53
53
|
_ as animatedSignal,
|
|
54
54
|
$ as bootstrapCanvas,
|
|
55
|
-
aa as
|
|
56
|
-
sa as
|
|
57
|
-
ea as
|
|
58
|
-
ta as
|
|
55
|
+
aa as checkDependencies,
|
|
56
|
+
sa as computed,
|
|
57
|
+
ea as cond,
|
|
58
|
+
ta as createComponent,
|
|
59
|
+
ia as currentSubscriptionsTracker,
|
|
59
60
|
oa as effect,
|
|
60
61
|
ra as focusManager,
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
na as h,
|
|
63
|
+
ca as isAnimatedSignal,
|
|
63
64
|
la as isArraySubject,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
ua as isComputed,
|
|
66
|
+
pa as isElement,
|
|
67
|
+
ma as isElementFrozen,
|
|
68
|
+
Sa as isObjectSubject,
|
|
69
|
+
da as isObservable,
|
|
69
70
|
ga as isPrimitive,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
Ca as isSignal,
|
|
72
|
+
ba as isTrigger,
|
|
73
|
+
ha as linkedSignal,
|
|
74
|
+
ka as loop,
|
|
75
|
+
wa as mount,
|
|
76
|
+
Da as mountTracker,
|
|
77
|
+
Ea as on,
|
|
78
|
+
ja as registerAllComponents,
|
|
79
|
+
Fa as registerComponent,
|
|
80
|
+
Ta as signal,
|
|
81
|
+
fa as tick,
|
|
82
|
+
va as trigger,
|
|
83
|
+
ya as untracked,
|
|
84
|
+
Oa as useDefineProps,
|
|
85
|
+
xa as useFocusChange,
|
|
86
|
+
Ma as useFocusIndex,
|
|
87
|
+
Aa as useFocusedElement,
|
|
88
|
+
Pa as useProps,
|
|
89
|
+
Va as waitForDependencies
|
|
88
90
|
};
|
|
89
91
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/src/engine/reactive.ts
CHANGED
|
@@ -120,6 +120,54 @@ export function registerAllComponents() {
|
|
|
120
120
|
componentsRegistered = true;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Checks if all dependencies are ready (not undefined).
|
|
125
|
+
* Handles signals synchronously and promises asynchronously.
|
|
126
|
+
* For reactive signals, sets up subscriptions to mount when all become ready.
|
|
127
|
+
*
|
|
128
|
+
* @param deps - Array of signals, promises, or direct values
|
|
129
|
+
* @returns Promise<boolean> - true if all dependencies are ready
|
|
130
|
+
*/
|
|
131
|
+
export async function checkDependencies(
|
|
132
|
+
deps: any[]
|
|
133
|
+
): Promise<boolean> {
|
|
134
|
+
const values = await Promise.all(
|
|
135
|
+
deps.map(async (dep) => {
|
|
136
|
+
if (isSignal(dep)) {
|
|
137
|
+
return dep(); // Read current signal value
|
|
138
|
+
} else if (isPromise(dep)) {
|
|
139
|
+
return await dep; // Await promise resolution
|
|
140
|
+
}
|
|
141
|
+
return dep; // Direct value
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
return values.every((v) => v !== undefined);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function waitForDependencies(deps: any[]): Promise<void> {
|
|
148
|
+
return new Promise(async (resolve) => {
|
|
149
|
+
const ready = await checkDependencies(deps);
|
|
150
|
+
if (ready) {
|
|
151
|
+
resolve();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const signalDeps = deps.filter((dep) => isSignal(dep));
|
|
156
|
+
if (signalDeps.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const signalObservables = signalDeps.map((sig) => sig.observable);
|
|
161
|
+
const subscription = combineLatest(signalObservables).subscribe(async () => {
|
|
162
|
+
const allReady = await checkDependencies(deps);
|
|
163
|
+
if (allReady) {
|
|
164
|
+
subscription.unsubscribe();
|
|
165
|
+
resolve();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
123
171
|
/**
|
|
124
172
|
* Checks if an element is currently frozen.
|
|
125
173
|
* An element is frozen when the `freeze` prop is set to `true` (either as a boolean or Signal<boolean>),
|
|
@@ -376,22 +424,12 @@ export function createComponent(tag: string, props?: Props): Element {
|
|
|
376
424
|
* @param deps - Array of signals, promises, or direct values
|
|
377
425
|
* @returns Promise<boolean> - true if all dependencies are ready
|
|
378
426
|
*/
|
|
379
|
-
async function checkDependencies(
|
|
380
|
-
deps: any[]
|
|
381
|
-
): Promise<boolean> {
|
|
382
|
-
const values = await Promise.all(
|
|
383
|
-
deps.map(async (dep) => {
|
|
384
|
-
if (isSignal(dep)) {
|
|
385
|
-
return dep(); // Read current signal value
|
|
386
|
-
} else if (isPromise(dep)) {
|
|
387
|
-
return await dep; // Await promise resolution
|
|
388
|
-
}
|
|
389
|
-
return dep; // Direct value
|
|
390
|
-
})
|
|
391
|
-
);
|
|
392
|
-
return values.every((v) => v !== undefined);
|
|
393
|
-
}
|
|
394
427
|
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Sets up subscriptions to reactive signal dependencies.
|
|
431
|
+
* When all signals become defined, mounts the component.
|
|
432
|
+
*/
|
|
395
433
|
/**
|
|
396
434
|
* Sets up subscriptions to reactive signal dependencies.
|
|
397
435
|
* When all signals become defined, mounts the component.
|
package/src/engine/signal.ts
CHANGED
|
@@ -2,8 +2,10 @@ import {
|
|
|
2
2
|
Observable,
|
|
3
3
|
Subscription
|
|
4
4
|
} from "rxjs";
|
|
5
|
+
import { isSignal } from "@signe/reactive";
|
|
5
6
|
import type { Element } from "./reactive";
|
|
6
|
-
import { isElementFrozen } from "./reactive";
|
|
7
|
+
import { isElementFrozen, waitForDependencies } from "./reactive";
|
|
8
|
+
import { isPromise } from "./utils";
|
|
7
9
|
import { Tick } from "../directives/Scheduler";
|
|
8
10
|
import { Container } from "../components";
|
|
9
11
|
|
|
@@ -22,16 +24,16 @@ export let mountTracker: MountFunction | null = null;
|
|
|
22
24
|
* @param {(element: Element) => void} fn - The function to be called on mount.
|
|
23
25
|
* @example
|
|
24
26
|
* ```ts
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
+
* mount((el) => {
|
|
28
|
+
* console.log('mounted', el);
|
|
27
29
|
* });
|
|
28
30
|
* ```
|
|
29
31
|
* Unmount the component by returning a function:
|
|
30
32
|
* ```ts
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
+
* mount((el) => {
|
|
34
|
+
* console.log('mounted', el);
|
|
33
35
|
* return () => {
|
|
34
|
-
*
|
|
36
|
+
* console.log('unmounted', el);
|
|
35
37
|
* }
|
|
36
38
|
* });
|
|
37
39
|
* ```
|
|
@@ -45,8 +47,8 @@ export function mount(fn: (element: Element) => void) {
|
|
|
45
47
|
* @param {(tickValue: Tick, element: Element) => void} fn - The function to be called on each tick.
|
|
46
48
|
* @example
|
|
47
49
|
* ```ts
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
+
* tick((tickValue, el) => {
|
|
51
|
+
* console.log('tick', tickValue, el);
|
|
50
52
|
* });
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
@@ -78,29 +80,29 @@ export function tick(fn: (tickValue: Tick, element: Element) => void) {
|
|
|
78
80
|
* @returns {ReturnType<C>}
|
|
79
81
|
* @example
|
|
80
82
|
* ```ts
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
* const el = h(MyComponent, {
|
|
84
|
+
* x: 100,
|
|
85
|
+
* y: 100,
|
|
86
|
+
* });
|
|
85
87
|
* ```
|
|
86
88
|
*
|
|
87
89
|
* with children:
|
|
88
90
|
* ```ts
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
* const el = h(MyComponent, {
|
|
92
|
+
* x: 100,
|
|
93
|
+
* y: 100,
|
|
94
|
+
* },
|
|
95
|
+
* h(MyChildComponent, {
|
|
96
|
+
* x: 50,
|
|
97
|
+
* y: 50,
|
|
98
|
+
* }),
|
|
97
99
|
* );
|
|
98
100
|
* ```
|
|
99
101
|
*/
|
|
100
|
-
|
|
102
|
+
function _h<C extends ComponentFunction<any>>(
|
|
101
103
|
componentFunction: C | Element,
|
|
102
104
|
props: Parameters<C>[0] = {} as Parameters<C>[0],
|
|
103
|
-
|
|
105
|
+
children: any[]
|
|
104
106
|
): ReturnType<C> {
|
|
105
107
|
const allSubscriptions = new Set<Subscription>();
|
|
106
108
|
const allMounts = new Set<MountFunction>();
|
|
@@ -124,7 +126,7 @@ export function h<C extends ComponentFunction<any>>(
|
|
|
124
126
|
component = componentFunction[0]
|
|
125
127
|
}
|
|
126
128
|
else {
|
|
127
|
-
component =
|
|
129
|
+
component = _h(Container, {}, componentFunction) as Element
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
else if ('tag' in componentFunction) {
|
|
@@ -167,3 +169,58 @@ export function h<C extends ComponentFunction<any>>(
|
|
|
167
169
|
|
|
168
170
|
return component as ReturnType<C>;
|
|
169
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Add tracking for subscriptions and mounts, then create an element from a component function.
|
|
175
|
+
* @template C
|
|
176
|
+
* @param {C} componentFunction - The component function to create an element from.
|
|
177
|
+
* @param {Parameters<C>[0]} [props={}] - The props to pass to the component function.
|
|
178
|
+
* @param {...any[]} children - The children elements of the component.
|
|
179
|
+
* @returns {ReturnType<C>}
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const el = h(MyComponent, {
|
|
183
|
+
* x: 100,
|
|
184
|
+
* y: 100,
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* with children:
|
|
189
|
+
* ```ts
|
|
190
|
+
* const el = h(MyComponent, {
|
|
191
|
+
* x: 100,
|
|
192
|
+
* y: 100,
|
|
193
|
+
* },
|
|
194
|
+
* h(MyChildComponent, {
|
|
195
|
+
* x: 50,
|
|
196
|
+
* y: 50,
|
|
197
|
+
* }),
|
|
198
|
+
* );
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function h<C extends ComponentFunction<any>>(
|
|
202
|
+
componentFunction: C | Element,
|
|
203
|
+
props: Parameters<C>[0] = {} as Parameters<C>[0],
|
|
204
|
+
...children: any[]
|
|
205
|
+
): ReturnType<C> {
|
|
206
|
+
if (props?.dependencies) {
|
|
207
|
+
const hasPromise = props.dependencies.some(isPromise);
|
|
208
|
+
if (!hasPromise) {
|
|
209
|
+
const allReady = props.dependencies.every(dep => {
|
|
210
|
+
if (isSignal(dep)) return dep() !== undefined;
|
|
211
|
+
return dep !== undefined;
|
|
212
|
+
});
|
|
213
|
+
if (allReady) {
|
|
214
|
+
return _h(componentFunction, props, children);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return new Observable(subscriber => {
|
|
219
|
+
waitForDependencies(props.dependencies).then(() => {
|
|
220
|
+
const el = _h(componentFunction, props, children);
|
|
221
|
+
subscriber.next(el);
|
|
222
|
+
});
|
|
223
|
+
}) as any;
|
|
224
|
+
}
|
|
225
|
+
return _h(componentFunction, props, children);
|
|
226
|
+
}
|