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/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { h as a } from "./index-BnuKipxl.js";
2
- import { A as r, _ as o, $ as n, t as l, x as c, v as p, C as S, d as m, Y as u, Z as d, an as g, f as b, D as C, am as k, ak as h, y as j, j as T, G as w, w as D, c as E, I as f, a0 as v, J as y, K as O, M as P, X as V, O as x, P as A, al as B, R as G, H, S as M, g as F, e as J, L as N, B as R, Q as q, U as z, T as I, z as K, b as U, N as L, W as Q, V as W, aj as X, ai as Y, ag as Z, k as _, a7 as $, a5 as aa, a8 as sa, l as ea, ac as ta, ah as ia, m as ra, n as oa, a1 as na, a4 as la, o as ca, i as pa, a2 as Sa, p as ma, ad as ua, q as da, a6 as ga, aa as ba, a9 as Ca, af as ka, a3 as ha, s as ja, ab as Ta, ae as wa, r as Da, a as Ea, u as fa } from "./index-BnuKipxl.js";
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
- d as DOMElement,
15
- g as DisplayObject,
16
- b as Drag,
17
- C as Drop,
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
- P as Mesh,
31
- V as NineSliceSprite,
32
- x as ObjectSubject,
33
- A as ParticlesEmitter,
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
- da as linkedSignal,
70
- ga as loop,
71
- ba as mount,
72
- Ca as mountTracker,
69
+ ga as linkedSignal,
70
+ da as loop,
71
+ Ca as mount,
72
+ ba as mountTracker,
73
73
  ka as on,
74
- ha as registerComponent,
75
- ja as signal,
76
- Ta as tick,
77
- wa as trigger,
78
- Da as untracked,
79
- Ea as useDefineProps,
80
- fa as useProps
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasengine",
3
- "version": "2.0.0-beta.41",
3
+ "version": "2.0.0-beta.42",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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?: ApplicationOptions) => {
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
- ...(options ?? {})
88
+ ...appOptions
22
89
  });
23
90
  const canvasElement = await h(canvas);
24
91
  if (canvasElement.tag != 'Canvas') {
@@ -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'