canvasengine 2.0.0-beta.3 → 2.0.0-beta.5

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.d.ts CHANGED
@@ -5,7 +5,7 @@ import { Subscription, Subject, Observable } from 'rxjs';
5
5
  export { isObservable } from 'rxjs';
6
6
  import { Node } from 'yoga-layout';
7
7
  import * as PIXI from 'pixi.js';
8
- import { ObservablePoint, Graphics as Graphics$1, TextStyle, Texture, Matrix } from 'pixi.js';
8
+ import { ObservablePoint, Graphics as Graphics$1, Texture, TextStyle, Matrix } from 'pixi.js';
9
9
  export { Howler } from 'howler';
10
10
  import * as popmotion from 'popmotion';
11
11
 
@@ -749,10 +749,26 @@ interface SpritePropsWithSheet extends Omit<SpriteProps, "image" | "rectangle">
749
749
  params?: any;
750
750
  onFinish?: () => void;
751
751
  };
752
+ loader?: {
753
+ onProgress?: (progress: number) => void;
754
+ onComplete?: (texture: Texture) => void;
755
+ };
752
756
  }
753
757
  type SpritePropTypes = SpritePropsWithImage | SpritePropsWithSheet;
754
758
  declare const Sprite: ComponentFunction<SpritePropTypes>;
755
759
 
760
+ interface VideoProps {
761
+ source: string;
762
+ paused?: boolean;
763
+ loop?: boolean;
764
+ muted?: boolean;
765
+ loader?: {
766
+ onComplete?: (texture: Texture) => void;
767
+ onProgress?: (progress: number) => void;
768
+ };
769
+ }
770
+ declare function Video(props: VideoProps): Element<ComponentInstance> | Promise<Element<ComponentInstance>>;
771
+
756
772
  interface TextProps extends DisplayObjectProps {
757
773
  text?: string;
758
774
  style?: Partial<TextStyle>;
@@ -813,15 +829,53 @@ declare function NineSliceSprite(props: NineSliceSpriteProps): Element<Component
813
829
 
814
830
  interface Listen<T = any> {
815
831
  config: T | undefined;
816
- seed: number;
832
+ seed: {
833
+ config: T | undefined;
834
+ value: number;
835
+ resolve: (value: any) => void;
836
+ };
817
837
  }
818
838
  interface Trigger<T = any> {
819
- start: () => void;
839
+ start: () => Promise<void>;
820
840
  listen: () => Listen<T> | undefined;
821
841
  }
842
+ /**
843
+ * Checks if the given argument is a Trigger object
844
+ * @param arg - The value to check
845
+ * @returns True if the argument is a Trigger object
846
+ */
822
847
  declare function isTrigger(arg: any): arg is Trigger<any>;
823
- declare function trigger<T = any>(config?: T): Trigger<T>;
824
- declare function on(triggerSignal: any, callback: (config: any) => void): void;
848
+ /**
849
+ * Creates a new trigger that can be used to pass data between components
850
+ * @param globalConfig - Optional configuration data to be passed when the trigger is activated
851
+ * @returns A Trigger object with start and listen methods
852
+ * @example
853
+ * ```ts
854
+ * const myTrigger = trigger()
855
+ *
856
+ * on(myTrigger, (data) => {
857
+ * console.log('Triggered with data:', data)
858
+ * })
859
+ *
860
+ * myTrigger.start({ message: 'Hello' })
861
+ * ```
862
+ */
863
+ declare function trigger<T = any>(globalConfig?: T): Trigger<T>;
864
+ /**
865
+ * Subscribes to a trigger and executes a callback when the trigger is activated
866
+ * @param triggerSignal - The trigger to subscribe to
867
+ * @param callback - Function to execute when the trigger is activated
868
+ * @throws Error if triggerSignal is not a valid trigger
869
+ * @example
870
+ * ```ts
871
+ * const click = trigger()
872
+ *
873
+ * on(click, () => {
874
+ * console.log('Click triggered')
875
+ * })
876
+ * ```
877
+ */
878
+ declare function on(triggerSignal: any, callback: (config: any) => void | Promise<void>): void;
825
879
 
826
880
  /**
827
881
  * Bootstraps a canvas element and renders it to the DOM.
@@ -891,6 +945,14 @@ declare const Easing: {
891
945
  bounceOut: (p: number) => number;
892
946
  };
893
947
 
948
+ /**
949
+ * Creates a radial gradient texture that can be used in PixiJS.
950
+ * @example
951
+ * const gradient = new RadialGradient(size, size, 0, size, size, 0);
952
+ * gradient.addColorStop(0, "rgba(255, 255, 0, 1)");
953
+ * gradient.addColorStop(0.5, "rgba(255, 255, 0, 0.3)");
954
+ * gradient.addColorStop(0.8, "rgba(255, 255, 0, 0)");
955
+ */
894
956
  declare class RadialGradient {
895
957
  private x0;
896
958
  private y0;
@@ -905,8 +967,29 @@ declare class RadialGradient {
905
967
  private texture;
906
968
  transform: Matrix;
907
969
  size: number;
970
+ /**
971
+ * Creates a new RadialGradient instance
972
+ * @param x0 - The x-coordinate of the starting circle
973
+ * @param y0 - The y-coordinate of the starting circle
974
+ * @param x1 - The x-coordinate of the ending circle
975
+ * @param y1 - The y-coordinate of the ending circle
976
+ * @param x2 - The x-coordinate for gradient transformation
977
+ * @param y2 - The y-coordinate for gradient transformation
978
+ * @param focalPoint - The focal point of the gradient (0-1), defaults to 0
979
+ */
908
980
  constructor(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, focalPoint?: number);
981
+ /**
982
+ * Adds a color stop to the gradient
983
+ * @param offset - The position of the color stop (0-1)
984
+ * @param color - The color value (any valid CSS color string)
985
+ */
909
986
  addColorStop(offset: number, color: string): void;
987
+ /**
988
+ * Renders the gradient and returns the texture with its transformation matrix
989
+ * @param options - Render options
990
+ * @param options.translate - Optional translation coordinates
991
+ * @returns Object containing the texture and transformation matrix
992
+ */
910
993
  render({ translate }?: {
911
994
  translate?: {
912
995
  x: number;
@@ -918,4 +1001,101 @@ declare class RadialGradient {
918
1001
  };
919
1002
  }
920
1003
 
921
- export { type AnimatedSignal, type AnimatedState, type ArrayChange, Canvas, Circle, type ComponentFunction, type ComponentInstance, Container, DisplayObject, EVENTS, Easing, type Element, Ellipse, Graphics, NineSliceSprite, ParticlesEmitter, type Props, RadialGradient, Rect, Scene, Sprite, Text, TilingSprite, Triangle, Viewport, animatedSignal, bootstrapCanvas, cond, createComponent, currentSubscriptionsTracker, h, isAnimatedSignal, isElement, isPrimitive, isTrigger, loop, mount, mountTracker, on, registerComponent, Svg as svg, tick, trigger, useDefineProps, useProps };
1004
+ /**
1005
+ * Checks if code is running in a browser environment
1006
+ * @returns {boolean} True if running in browser, false otherwise
1007
+ */
1008
+ declare function isBrowser(): boolean;
1009
+ /**
1010
+ * Returns current high-resolution timestamp
1011
+ * @returns {number} Current time in milliseconds
1012
+ */
1013
+ declare function preciseNow(): number;
1014
+ /**
1015
+ * Converts frames per second to milliseconds
1016
+ * @param {number} fps - Frames per second
1017
+ * @returns {number} Milliseconds per frame
1018
+ */
1019
+ declare function fps2ms(fps: number): number;
1020
+ /**
1021
+ * Checks if a value is a Promise
1022
+ * @param {any} value - Value to check
1023
+ * @returns {boolean} True if value is a Promise, false otherwise
1024
+ */
1025
+ declare function isPromise(value: any): boolean;
1026
+ declare function arrayEquals(a: any[], b: any[]): boolean;
1027
+ /**
1028
+ * Checks if a value is a function
1029
+ * @param {unknown} val - Value to check
1030
+ * @returns {boolean} True if value is a function, false otherwise
1031
+ */
1032
+ declare function isFunction(val: unknown): boolean;
1033
+ /**
1034
+ * Checks if a value is a plain object
1035
+ * @param {unknown} val - Value to check
1036
+ * @returns {boolean} True if value is an object (not null and not array), false otherwise
1037
+ */
1038
+ declare function isObject(val: unknown): boolean;
1039
+ /**
1040
+ * Sets a value in an object using a dot notation path
1041
+ * @param {Record<string, any>} obj - Target object
1042
+ * @param {string | string[]} path - Path to set value at (e.g., 'a.b.c' or ['a', 'b', 'c'])
1043
+ * @param {any} value - Value to set
1044
+ * @param {boolean} onlyPlainObject - If true, only creates plain objects in path
1045
+ * @returns {Record<string, any>} Modified object
1046
+ */
1047
+ declare function set(obj: Record<string, any>, path: string | string[], value: any, onlyPlainObject?: boolean): Record<string, any>;
1048
+ /**
1049
+ * Gets a value from an object using a dot notation path
1050
+ * @param {Record<string, any>} obj - Source object
1051
+ * @param {string} path - Path to get value from (e.g., 'a.b.c')
1052
+ * @returns {any} Value at path or undefined if not found
1053
+ */
1054
+ declare function get(obj: Record<string, any>, path: string): any;
1055
+ /**
1056
+ * Logs a message to console
1057
+ * @param {any} text - Message to log
1058
+ */
1059
+ declare function log(text: any): void;
1060
+ /**
1061
+ * Logs an error message to console
1062
+ * @param {any} text - Error message to log
1063
+ */
1064
+ declare function error(text: any): void;
1065
+ /**
1066
+ * Sets the position of an ObservablePoint using various input formats
1067
+ * @param {ObservablePoint} observablePoint - The point to modify
1068
+ * @param {Object | number | [number, number]} point - New position value
1069
+ */
1070
+ declare function setObservablePoint(observablePoint: ObservablePoint, point: {
1071
+ x: number;
1072
+ y: number;
1073
+ } | number | [number, number]): void;
1074
+ /**
1075
+ * Calculates the Euclidean distance between two points
1076
+ * @param {number} x1 - X coordinate of first point
1077
+ * @param {number} y1 - Y coordinate of first point
1078
+ * @param {number} x2 - X coordinate of second point
1079
+ * @param {number} y2 - Y coordinate of second point
1080
+ * @returns {number} Distance between the points
1081
+ */
1082
+ declare function calculateDistance(x1: number, y1: number, x2: number, y2: number): number;
1083
+
1084
+ declare const utils_arrayEquals: typeof arrayEquals;
1085
+ declare const utils_calculateDistance: typeof calculateDistance;
1086
+ declare const utils_error: typeof error;
1087
+ declare const utils_fps2ms: typeof fps2ms;
1088
+ declare const utils_get: typeof get;
1089
+ declare const utils_isBrowser: typeof isBrowser;
1090
+ declare const utils_isFunction: typeof isFunction;
1091
+ declare const utils_isObject: typeof isObject;
1092
+ declare const utils_isPromise: typeof isPromise;
1093
+ declare const utils_log: typeof log;
1094
+ declare const utils_preciseNow: typeof preciseNow;
1095
+ declare const utils_set: typeof set;
1096
+ declare const utils_setObservablePoint: typeof setObservablePoint;
1097
+ declare namespace utils {
1098
+ export { utils_arrayEquals as arrayEquals, utils_calculateDistance as calculateDistance, utils_error as error, utils_fps2ms as fps2ms, utils_get as get, utils_isBrowser as isBrowser, utils_isFunction as isFunction, utils_isObject as isObject, utils_isPromise as isPromise, utils_log as log, utils_preciseNow as preciseNow, utils_set as set, utils_setObservablePoint as setObservablePoint };
1099
+ }
1100
+
1101
+ export { type AnimatedSignal, type AnimatedState, type ArrayChange, Canvas, Circle, type ComponentFunction, type ComponentInstance, Container, DisplayObject, EVENTS, Easing, type Element, Ellipse, Graphics, NineSliceSprite, ParticlesEmitter, type Props, RadialGradient, Rect, Scene, Sprite, Text, TilingSprite, Triangle, utils as Utils, Video, Viewport, animatedSignal, bootstrapCanvas, cond, createComponent, currentSubscriptionsTracker, h, isAnimatedSignal, isElement, isPrimitive, isTrigger, loop, mount, mountTracker, on, registerComponent, Svg as svg, tick, trigger, useDefineProps, useProps };