canvasengine 2.0.0-beta.3 → 2.0.0-beta.31

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.
Files changed (130) hide show
  1. package/dist/DebugRenderer-DrlzuIVv.js +172 -0
  2. package/dist/DebugRenderer-DrlzuIVv.js.map +1 -0
  3. package/dist/components/Button.d.ts +136 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +18 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/Container.d.ts +80 -0
  8. package/dist/components/Container.d.ts.map +1 -0
  9. package/dist/components/DOMContainer.d.ts +77 -0
  10. package/dist/components/DOMContainer.d.ts.map +1 -0
  11. package/dist/components/DOMElement.d.ts +44 -0
  12. package/dist/components/DOMElement.d.ts.map +1 -0
  13. package/dist/components/DisplayObject.d.ts +82 -0
  14. package/dist/components/DisplayObject.d.ts.map +1 -0
  15. package/dist/components/Graphic.d.ts +65 -0
  16. package/dist/components/Graphic.d.ts.map +1 -0
  17. package/dist/components/Mesh.d.ts +202 -0
  18. package/dist/components/Mesh.d.ts.map +1 -0
  19. package/dist/components/NineSliceSprite.d.ts +17 -0
  20. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  21. package/dist/components/ParticleEmitter.d.ts +5 -0
  22. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  23. package/dist/components/Scene.d.ts +2 -0
  24. package/dist/components/Scene.d.ts.map +1 -0
  25. package/dist/components/Sprite.d.ts +174 -0
  26. package/dist/components/Sprite.d.ts.map +1 -0
  27. package/dist/components/Text.d.ts +21 -0
  28. package/dist/components/Text.d.ts.map +1 -0
  29. package/dist/components/TilingSprite.d.ts +18 -0
  30. package/dist/components/TilingSprite.d.ts.map +1 -0
  31. package/dist/components/Video.d.ts +15 -0
  32. package/dist/components/Video.d.ts.map +1 -0
  33. package/dist/components/Viewport.d.ts +106 -0
  34. package/dist/components/Viewport.d.ts.map +1 -0
  35. package/dist/components/index.d.ts +17 -0
  36. package/dist/components/index.d.ts.map +1 -0
  37. package/dist/components/types/DisplayObject.d.ts +106 -0
  38. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  39. package/dist/components/types/MouseEvent.d.ts +4 -0
  40. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  41. package/dist/components/types/Spritesheet.d.ts +366 -0
  42. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  43. package/dist/components/types/index.d.ts +5 -0
  44. package/dist/components/types/index.d.ts.map +1 -0
  45. package/dist/directives/Drag.d.ts +70 -0
  46. package/dist/directives/Drag.d.ts.map +1 -0
  47. package/dist/directives/KeyboardControls.d.ts +530 -0
  48. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  49. package/dist/directives/Scheduler.d.ts +36 -0
  50. package/dist/directives/Scheduler.d.ts.map +1 -0
  51. package/dist/directives/Sound.d.ts +26 -0
  52. package/dist/directives/Sound.d.ts.map +1 -0
  53. package/dist/directives/Transition.d.ts +11 -0
  54. package/dist/directives/Transition.d.ts.map +1 -0
  55. package/dist/directives/ViewportCull.d.ts +12 -0
  56. package/dist/directives/ViewportCull.d.ts.map +1 -0
  57. package/dist/directives/ViewportFollow.d.ts +19 -0
  58. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  59. package/dist/directives/index.d.ts +2 -0
  60. package/dist/directives/index.d.ts.map +1 -0
  61. package/dist/engine/animation.d.ts +59 -0
  62. package/dist/engine/animation.d.ts.map +1 -0
  63. package/dist/engine/bootstrap.d.ts +16 -0
  64. package/dist/engine/bootstrap.d.ts.map +1 -0
  65. package/dist/engine/directive.d.ts +14 -0
  66. package/dist/engine/directive.d.ts.map +1 -0
  67. package/dist/engine/reactive.d.ts +95 -0
  68. package/dist/engine/reactive.d.ts.map +1 -0
  69. package/dist/engine/signal.d.ts +72 -0
  70. package/dist/engine/signal.d.ts.map +1 -0
  71. package/dist/engine/trigger.d.ts +51 -0
  72. package/dist/engine/trigger.d.ts.map +1 -0
  73. package/dist/engine/utils.d.ts +90 -0
  74. package/dist/engine/utils.d.ts.map +1 -0
  75. package/dist/hooks/addContext.d.ts +2 -0
  76. package/dist/hooks/addContext.d.ts.map +1 -0
  77. package/dist/hooks/useProps.d.ts +42 -0
  78. package/dist/hooks/useProps.d.ts.map +1 -0
  79. package/dist/hooks/useRef.d.ts +5 -0
  80. package/dist/hooks/useRef.d.ts.map +1 -0
  81. package/dist/index-DNDNQN-q.js +11088 -0
  82. package/dist/index-DNDNQN-q.js.map +1 -0
  83. package/dist/index.d.ts +15 -919
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.global.js +29 -0
  86. package/dist/index.global.js.map +1 -0
  87. package/dist/index.js +63 -2950
  88. package/dist/index.js.map +1 -1
  89. package/dist/utils/Ease.d.ts +17 -0
  90. package/dist/utils/Ease.d.ts.map +1 -0
  91. package/dist/utils/RadialGradient.d.ts +58 -0
  92. package/dist/utils/RadialGradient.d.ts.map +1 -0
  93. package/dist/utils/functions.d.ts +2 -0
  94. package/dist/utils/functions.d.ts.map +1 -0
  95. package/index.d.ts +4 -0
  96. package/package.json +12 -7
  97. package/src/components/Button.ts +269 -0
  98. package/src/components/Canvas.ts +53 -45
  99. package/src/components/Container.ts +2 -2
  100. package/src/components/DOMContainer.ts +123 -0
  101. package/src/components/DOMElement.ts +421 -0
  102. package/src/components/DisplayObject.ts +283 -190
  103. package/src/components/Graphic.ts +200 -34
  104. package/src/components/Mesh.ts +222 -0
  105. package/src/components/NineSliceSprite.ts +4 -1
  106. package/src/components/ParticleEmitter.ts +12 -8
  107. package/src/components/Sprite.ts +92 -22
  108. package/src/components/Text.ts +34 -14
  109. package/src/components/Video.ts +110 -0
  110. package/src/components/Viewport.ts +59 -43
  111. package/src/components/index.ts +7 -2
  112. package/src/components/types/DisplayObject.ts +30 -0
  113. package/src/directives/Drag.ts +357 -52
  114. package/src/directives/KeyboardControls.ts +3 -1
  115. package/src/directives/Sound.ts +94 -31
  116. package/src/directives/ViewportFollow.ts +35 -7
  117. package/src/engine/animation.ts +41 -5
  118. package/src/engine/bootstrap.ts +23 -3
  119. package/src/engine/directive.ts +2 -2
  120. package/src/engine/reactive.ts +542 -170
  121. package/src/engine/signal.ts +22 -2
  122. package/src/engine/trigger.ts +65 -9
  123. package/src/engine/utils.ts +97 -9
  124. package/src/hooks/useProps.ts +1 -1
  125. package/src/index.ts +4 -1
  126. package/src/utils/RadialGradient.ts +29 -0
  127. package/src/utils/functions.ts +7 -0
  128. package/testing/index.ts +12 -0
  129. package/tsconfig.json +17 -0
  130. package/vite.config.ts +39 -0
@@ -1,10 +1,11 @@
1
1
  import { effect, signal, type WritableSignal } from "@signe/reactive";
2
2
  import { animate as animatePopmotion } from "popmotion";
3
3
 
4
- interface AnimateOptions<T> {
4
+ export interface AnimateOptions<T> {
5
5
  duration?: number;
6
6
  ease?: (t: number) => number;
7
7
  onUpdate?: (value: T) => void;
8
+ onComplete?: () => void;
8
9
  }
9
10
 
10
11
  export interface AnimatedState<T> {
@@ -15,7 +16,7 @@ export interface AnimatedState<T> {
15
16
 
16
17
  export interface AnimatedSignal<T> extends Omit<WritableSignal<T>, 'set'> {
17
18
  (): T;
18
- set: (newValue: T) => void;
19
+ set: (newValue: T, options?: AnimateOptions<T>) => Promise<void>;
19
20
  animatedState: WritableSignal<AnimatedState<T>>;
20
21
  update: (updater: (value: T) => T) => void;
21
22
  }
@@ -60,7 +61,8 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
60
61
 
61
62
  function animatedSignal(): AnimatedState<T>;
62
63
  function animatedSignal(newValue: T): void;
63
- function animatedSignal(newValue?: T): AnimatedState<T> | void {
64
+ function animatedSignal(newValue: T, animationConfig: AnimateOptions<T>): void;
65
+ function animatedSignal(newValue?: T, animationConfig: AnimateOptions<T> = {}): AnimatedState<T> | void {
64
66
  if (newValue === undefined) {
65
67
  return privateSignal();
66
68
  }
@@ -82,6 +84,7 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
82
84
  // TODO
83
85
  duration: 20,
84
86
  ...options,
87
+ ...animationConfig,
85
88
  from: prevState.current,
86
89
  to: newValue,
87
90
  onUpdate: (value) => {
@@ -105,9 +108,42 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
105
108
  fn.update = (updater: (value: T) => any) => {
106
109
  animatedSignal(updater(privateSignal().current));
107
110
  }
108
- fn.set = (newValue: T) => {
109
- animatedSignal(newValue);
111
+ fn.set = async (newValue: T, animationConfig: AnimateOptions<T> = {}) => {
112
+ return new Promise<void>((resolve) => {
113
+ animatedSignal(newValue, {
114
+ ...animationConfig,
115
+ onComplete: resolve
116
+ });
117
+ })
110
118
  }
111
119
 
112
120
  return fn as any
121
+ }
122
+
123
+ /**
124
+ * Executes a sequence of animations. If an array is provided as an element in the sequence,
125
+ * those animations will be executed in parallel.
126
+ *
127
+ * @param sequence Array of animation functions or arrays of animation functions for parallel execution
128
+ * @returns Promise that resolves when all animations are complete
129
+ * @example
130
+ * ```ts
131
+ * await animatedSequence([
132
+ * () => value1.set(10),
133
+ * [
134
+ * () => value2.set(20),
135
+ * () => value3.set(30)
136
+ * ],
137
+ * () => value1.set(0)
138
+ * ])
139
+ * ```
140
+ */
141
+ export async function animatedSequence(sequence: ((() => Promise<void>) | (() => Promise<void>)[])[]) {
142
+ for (const item of sequence) {
143
+ if (Array.isArray(item)) {
144
+ await Promise.all(item.map(fn => fn()));
145
+ } else {
146
+ await item();
147
+ }
148
+ }
113
149
  }
@@ -1,4 +1,7 @@
1
+ import '@pixi/layout';
2
+ import { Application, ApplicationOptions } from "pixi.js";
1
3
  import { ComponentFunction, h } from "./signal";
4
+ import { useProps } from '../hooks/useProps';
2
5
 
3
6
  /**
4
7
  * Bootstraps a canvas element and renders it to the DOM.
@@ -8,12 +11,29 @@ import { ComponentFunction, h } from "./signal";
8
11
  * @returns A Promise that resolves to the rendered canvas element.
9
12
  * @throws {Error} If the provided element is not a Canvas component.
10
13
  */
11
- export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any>) => {
14
+ export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any>, options?: ApplicationOptions) => {
15
+
16
+ const app = new Application();
17
+ await app.init({
18
+ resizeTo: rootElement,
19
+ autoStart: false,
20
+ antialias: true,
21
+ ...(options ?? {})
22
+ });
12
23
  const canvasElement = await h(canvas);
13
24
  if (canvasElement.tag != 'Canvas') {
14
25
  throw new Error('Canvas is required');
15
26
  }
16
- (canvasElement as any).render(rootElement);
27
+ (canvasElement as any).render(rootElement, app);
17
28
 
18
- return canvasElement;
29
+ const { backgroundColor } = useProps(canvasElement.props, {
30
+ backgroundColor: 'black'
31
+ });
32
+
33
+ app.renderer.background.color = backgroundColor()
34
+
35
+ return {
36
+ canvasElement,
37
+ app
38
+ };
19
39
  };
@@ -3,10 +3,10 @@ import { Element } from "./reactive"
3
3
  export const directives: { [key: string]: any } = {}
4
4
 
5
5
  export abstract class Directive {
6
- abstract onDestroy();
6
+ abstract onDestroy(element: Element<any>);
7
7
  abstract onInit(element: Element<any>);
8
8
  abstract onMount(element: Element<any>);
9
- abstract onUpdate(props: any);
9
+ abstract onUpdate(props: any, element: Element<any>);
10
10
  }
11
11
 
12
12
  export function registerDirective(name: string, directive: any) {