canvasengine 2.0.0-beta.41 → 2.0.0-beta.42
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-BxfW34YG.js → DebugRenderer-BosXI2Pd.js} +2 -2
- package/dist/{DebugRenderer-BxfW34YG.js.map → DebugRenderer-BosXI2Pd.js.map} +1 -1
- package/dist/engine/bootstrap.d.ts +33 -1
- package/dist/engine/bootstrap.d.ts.map +1 -1
- package/dist/engine/reactive.d.ts +20 -0
- package/dist/engine/reactive.d.ts.map +1 -1
- package/dist/{index-BnuKipxl.js → index-DNwqVzaq.js} +797 -788
- package/dist/index-DNwqVzaq.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +6 -6
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +22 -21
- package/package.json +1 -1
- package/src/engine/bootstrap.ts +69 -2
- package/src/engine/reactive.ts +35 -0
- package/src/index.ts +1 -0
- package/dist/index-BnuKipxl.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as a } from "./index-
|
|
2
|
-
import { A as r,
|
|
1
|
+
import { h as a } from "./index-DNwqVzaq.js";
|
|
2
|
+
import { A as r, $ as o, a0 as n, v as l, y as c, w as p, C as S, d as m, Z as u, _ as g, ao as d, f as C, D as b, an as k, al as h, z as j, j as T, G as w, x as D, c as E, I as f, a1 as v, J as y, K as O, M as A, Y as P, O as V, P as x, am as B, R as G, L as H, S as M, g as F, e as J, N, H as R, U as q, W as z, T as I, B as K, b as U, Q as L, X as Q, V as W, ak as X, aj as Y, ah as Z, k as _, a8 as $, a6 as aa, a9 as sa, l as ea, ad as ta, ai as ia, m as ra, n as oa, a2 as na, a5 as la, o as ca, i as pa, a3 as Sa, p as ma, ae as ua, q as ga, a7 as da, ab as Ca, aa as ba, ag as ka, r as ha, a4 as ja, s as Ta, ac as wa, af as Da, t as Ea, a as fa, u as va } from "./index-DNwqVzaq.js";
|
|
3
3
|
const e = a.Howler;
|
|
4
4
|
export {
|
|
5
5
|
r as ArraySubject,
|
|
@@ -11,10 +11,10 @@ export {
|
|
|
11
11
|
S as ControlsBase,
|
|
12
12
|
m as ControlsDirective,
|
|
13
13
|
u as DOMContainer,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
g as DOMElement,
|
|
15
|
+
d as DisplayObject,
|
|
16
|
+
C as Drag,
|
|
17
|
+
b as Drop,
|
|
18
18
|
k as EVENTS,
|
|
19
19
|
h as Easing,
|
|
20
20
|
j as Ellipse,
|
|
@@ -27,10 +27,10 @@ export {
|
|
|
27
27
|
v as Joystick,
|
|
28
28
|
y as JoystickControls,
|
|
29
29
|
O as KeyboardControls,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
A as Mesh,
|
|
31
|
+
P as NineSliceSprite,
|
|
32
|
+
V as ObjectSubject,
|
|
33
|
+
x as ParticlesEmitter,
|
|
34
34
|
B as RadialGradient,
|
|
35
35
|
G as Rect,
|
|
36
36
|
H as Scene,
|
|
@@ -66,17 +66,18 @@ export {
|
|
|
66
66
|
Sa as isPrimitive,
|
|
67
67
|
ma as isSignal,
|
|
68
68
|
ua as isTrigger,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
ga as linkedSignal,
|
|
70
|
+
da as loop,
|
|
71
|
+
Ca as mount,
|
|
72
|
+
ba as mountTracker,
|
|
73
73
|
ka as on,
|
|
74
|
-
ha as
|
|
75
|
-
ja as
|
|
76
|
-
Ta as
|
|
77
|
-
wa as
|
|
78
|
-
Da as
|
|
79
|
-
Ea as
|
|
80
|
-
fa as
|
|
74
|
+
ha as registerAllComponents,
|
|
75
|
+
ja as registerComponent,
|
|
76
|
+
Ta as signal,
|
|
77
|
+
wa as tick,
|
|
78
|
+
Da as trigger,
|
|
79
|
+
Ea as untracked,
|
|
80
|
+
fa as useDefineProps,
|
|
81
|
+
va as useProps
|
|
81
82
|
};
|
|
82
83
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/src/engine/bootstrap.ts
CHANGED
|
@@ -2,23 +2,90 @@ import '@pixi/layout';
|
|
|
2
2
|
import { Application, ApplicationOptions } from "pixi.js";
|
|
3
3
|
import { ComponentFunction, h } from "./signal";
|
|
4
4
|
import { useProps } from '../hooks/useProps';
|
|
5
|
+
import { registerAllComponents, registerComponent } from './reactive';
|
|
6
|
+
|
|
7
|
+
// Import all components to ensure they are registered
|
|
8
|
+
// This is done here (not in reactive.ts) to avoid circular dependencies
|
|
9
|
+
// Components register themselves when their modules are imported
|
|
10
|
+
import '../components/Canvas';
|
|
11
|
+
import '../components/Container';
|
|
12
|
+
import '../components/Sprite';
|
|
13
|
+
import '../components/Text';
|
|
14
|
+
import '../components/Graphic';
|
|
15
|
+
import '../components/Mesh';
|
|
16
|
+
import '../components/Viewport';
|
|
17
|
+
import '../components/TilingSprite';
|
|
18
|
+
import '../components/NineSliceSprite';
|
|
19
|
+
import '../components/DOMContainer';
|
|
20
|
+
import '../components/DOMElement';
|
|
21
|
+
import '../components/ParticleEmitter';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extended options for bootstrapCanvas that includes component registration configuration.
|
|
25
|
+
*
|
|
26
|
+
* @property components - Optional mapping of component names to their classes (can include mocks for testing)
|
|
27
|
+
* @property autoRegister - If true (default), registers all default components before applying custom components. If false, only registers the specified components.
|
|
28
|
+
*/
|
|
29
|
+
export interface BootstrapOptions extends ApplicationOptions {
|
|
30
|
+
components?: {
|
|
31
|
+
[name: string]: any; // ComponentClass
|
|
32
|
+
};
|
|
33
|
+
autoRegister?: boolean; // true by default if components is not provided
|
|
34
|
+
}
|
|
5
35
|
|
|
6
36
|
/**
|
|
7
37
|
* Bootstraps a canvas element and renders it to the DOM.
|
|
8
38
|
*
|
|
9
39
|
* @param rootElement - The HTML element where the canvas will be rendered. Can be null.
|
|
10
40
|
* @param canvas - A Promise that resolves to an Element representing the canvas component.
|
|
41
|
+
* @param options - Optional bootstrap options including ApplicationOptions and component registration configuration.
|
|
11
42
|
* @returns A Promise that resolves to the rendered canvas element.
|
|
12
43
|
* @throws {Error} If the provided element is not a Canvas component.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Default: all components registered automatically
|
|
48
|
+
* await bootstrapCanvas(rootElement, MyComponent, {
|
|
49
|
+
* width: 800,
|
|
50
|
+
* height: 600
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // With mocks for testing
|
|
57
|
+
* import { mockComponents } from '@canvasengine/testing';
|
|
58
|
+
* await bootstrapCanvas(rootElement, MyComponent, {
|
|
59
|
+
* components: mockComponents,
|
|
60
|
+
* autoRegister: false
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
13
63
|
*/
|
|
14
|
-
export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any>, options?:
|
|
64
|
+
export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any>, options?: BootstrapOptions) => {
|
|
65
|
+
// Extract component registration options
|
|
66
|
+
const { components, autoRegister, ...appOptions } = options ?? {};
|
|
67
|
+
|
|
68
|
+
// Handle component registration
|
|
69
|
+
if (components) {
|
|
70
|
+
if (autoRegister !== false) {
|
|
71
|
+
// Register all default components first, then override with custom ones
|
|
72
|
+
registerAllComponents();
|
|
73
|
+
}
|
|
74
|
+
// Register the specified components (overriding defaults if autoRegister is true)
|
|
75
|
+
Object.entries(components).forEach(([name, componentClass]) => {
|
|
76
|
+
registerComponent(name, componentClass);
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
// Default behavior: register all components
|
|
80
|
+
registerAllComponents();
|
|
81
|
+
}
|
|
15
82
|
|
|
16
83
|
const app = new Application();
|
|
17
84
|
await app.init({
|
|
18
85
|
resizeTo: rootElement,
|
|
19
86
|
autoStart: false,
|
|
20
87
|
antialias: true,
|
|
21
|
-
...
|
|
88
|
+
...appOptions
|
|
22
89
|
});
|
|
23
90
|
const canvasElement = await h(canvas);
|
|
24
91
|
if (canvasElement.tag != 'Canvas') {
|
package/src/engine/reactive.ts
CHANGED
|
@@ -84,6 +84,41 @@ export function registerComponent(name, component) {
|
|
|
84
84
|
components[name] = component;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
// Track if components have been registered to avoid duplicate imports
|
|
88
|
+
let componentsRegistered = false;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Registers all default CanvasEngine components.
|
|
92
|
+
*
|
|
93
|
+
* This function imports and registers all core components that are available by default.
|
|
94
|
+
* It's called automatically by bootstrapCanvas() if no custom component configuration is provided.
|
|
95
|
+
*
|
|
96
|
+
* Components register themselves when their modules are imported, so this function ensures
|
|
97
|
+
* all component modules are loaded. Since components call registerComponent() at module load time,
|
|
98
|
+
* importing them will automatically register them synchronously.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Register all default components manually
|
|
103
|
+
* registerAllComponents();
|
|
104
|
+
*
|
|
105
|
+
* // Now you can use any component
|
|
106
|
+
* const sprite = createComponent('Sprite', { image: 'hero.png' });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export function registerAllComponents() {
|
|
110
|
+
if (componentsRegistered) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Components are registered when their modules are imported
|
|
115
|
+
// Since bootstrap.ts imports all components, they should already be registered
|
|
116
|
+
// when bootstrapCanvas() is called. This function just marks that registration
|
|
117
|
+
// has been attempted. If components aren't registered yet, they will be when
|
|
118
|
+
// bootstrap.ts imports them (which happens before bootstrapCanvas() is called).
|
|
119
|
+
componentsRegistered = true;
|
|
120
|
+
}
|
|
121
|
+
|
|
87
122
|
/**
|
|
88
123
|
* Checks if an element is currently frozen.
|
|
89
124
|
* An element is frozen when the `freeze` prop is set to `true` (either as a boolean or Signal<boolean>),
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from '@signe/reactive'
|
|
|
4
4
|
export { Howler } from 'howler'
|
|
5
5
|
export * from './components'
|
|
6
6
|
export * from './engine/reactive'
|
|
7
|
+
export { registerAllComponents } from './engine/reactive'
|
|
7
8
|
export * from './engine/signal'
|
|
8
9
|
export * from './engine/trigger'
|
|
9
10
|
export * from './engine/bootstrap'
|