canvasengine 2.0.0-beta.1 → 2.0.0-beta.2

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 DELETED
@@ -1,846 +0,0 @@
1
- import { WritableSignal, Signal, WritableArraySignal } from '@signe/reactive';
2
- export * from '@signe/reactive';
3
- import { Subscription, Subject, Observable } from 'rxjs';
4
- export { Howler } from 'howler';
5
- import * as PIXI from 'pixi.js';
6
- import { Graphics as Graphics$1, TextStyle, Texture } from 'pixi.js';
7
- import * as popmotion from 'popmotion';
8
-
9
- interface AnimateOptions<T> {
10
- duration?: number;
11
- ease?: (t: number) => number;
12
- onUpdate?: (value: T) => void;
13
- }
14
- interface AnimatedState<T> {
15
- current: T;
16
- start: T;
17
- end: T;
18
- }
19
- interface AnimatedSignal<T> extends Omit<WritableSignal<T>, 'set'> {
20
- (): T;
21
- set: (newValue: T) => void;
22
- animatedState: WritableSignal<AnimatedState<T>>;
23
- update: (updater: (value: T) => T) => void;
24
- }
25
- declare function isAnimatedSignal(signal: WritableSignal<any>): boolean;
26
- /**
27
- * Creates an animated signal with the given initial value and animation options.
28
- * It's a writable signal that can be animated using popmotion. Properties of the animated signal are:
29
- * - current: the current value of the signal.
30
- * - start: the start value of the animation.
31
- * - end: the end value of the animation.
32
- *
33
- * @param initialValue The initial value of the signal.
34
- * @param options The animation options.
35
- * @returns The animated signal.
36
- * @example
37
- * const animatedValue = animatedSignal(0, { duration: 1000 });
38
- * animatedValue.set(10);
39
- * animatedValue.update((value) => value + 1);
40
- * console.log(animatedValue()); // 11
41
- *
42
- * animatedValue.animatedState() // { current: 10, start: 10, end: 11 }
43
- */
44
- declare function animatedSignal<T>(initialValue: T, options?: AnimateOptions<T>): AnimatedSignal<T>;
45
-
46
- type SignalOrPrimitive<T> = T | Signal<T> | AnimatedSignal<T>;
47
-
48
- type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
49
- type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
50
- type Size = number | `${number}%`;
51
- type EdgeSize = SignalOrPrimitive<Size | [Size, Size] | [Size, Size, Size, Size]>;
52
- interface DisplayObjectProps {
53
- ref?: string;
54
- x?: SignalOrPrimitive<number>;
55
- y?: SignalOrPrimitive<number>;
56
- width?: SignalOrPrimitive<Size>;
57
- height?: SignalOrPrimitive<Size>;
58
- children?: any[];
59
- flexDirection?: FlexDirection;
60
- justifyContent?: JustifyContent;
61
- alpha?: SignalOrPrimitive<number>;
62
- margin?: EdgeSize;
63
- padding?: EdgeSize;
64
- border?: EdgeSize;
65
- absolute?: SignalOrPrimitive<boolean>;
66
- scale?: SignalOrPrimitive<{
67
- x: number;
68
- y: number;
69
- } | number>;
70
- anchor?: SignalOrPrimitive<{
71
- x: number;
72
- y: number;
73
- }>;
74
- skew?: SignalOrPrimitive<{
75
- x: number;
76
- y: number;
77
- }>;
78
- tint?: SignalOrPrimitive<number>;
79
- rotation?: SignalOrPrimitive<number>;
80
- angle?: SignalOrPrimitive<number>;
81
- zIndex?: SignalOrPrimitive<number>;
82
- roundPixels?: SignalOrPrimitive<boolean>;
83
- cursor?: SignalOrPrimitive<string>;
84
- visible?: SignalOrPrimitive<boolean>;
85
- pivot?: SignalOrPrimitive<{
86
- x: number;
87
- y: number;
88
- }>;
89
- filters?: any[];
90
- blendMode?: SignalOrPrimitive<PIXI.BLEND_MODES>;
91
- click?: PIXI.FederatedEventHandler;
92
- mousedown?: PIXI.FederatedEventHandler;
93
- mouseenter?: PIXI.FederatedEventHandler;
94
- mouseleave?: PIXI.FederatedEventHandler;
95
- mousemove?: PIXI.FederatedEventHandler;
96
- mouseout?: PIXI.FederatedEventHandler;
97
- mouseover?: PIXI.FederatedEventHandler;
98
- mouseup?: PIXI.FederatedEventHandler;
99
- mouseupoutside?: PIXI.FederatedEventHandler;
100
- pointercancel?: PIXI.FederatedEventHandler;
101
- pointerdown?: PIXI.FederatedEventHandler;
102
- pointerenter?: PIXI.FederatedEventHandler;
103
- pointerleave?: PIXI.FederatedEventHandler;
104
- pointermove?: PIXI.FederatedEventHandler;
105
- pointerout?: PIXI.FederatedEventHandler;
106
- pointerover?: PIXI.FederatedEventHandler;
107
- pointertap?: PIXI.FederatedEventHandler;
108
- pointerup?: PIXI.FederatedEventHandler;
109
- pointerupoutside?: PIXI.FederatedEventHandler;
110
- rightclick?: PIXI.FederatedEventHandler;
111
- rightdown?: PIXI.FederatedEventHandler;
112
- rightup?: PIXI.FederatedEventHandler;
113
- rightupoutside?: PIXI.FederatedEventHandler;
114
- tap?: PIXI.FederatedEventHandler;
115
- touchcancel?: PIXI.FederatedEventHandler;
116
- touchend?: PIXI.FederatedEventHandler;
117
- touchendoutside?: PIXI.FederatedEventHandler;
118
- touchmove?: PIXI.FederatedEventHandler;
119
- touchstart?: PIXI.FederatedEventHandler;
120
- wheel?: PIXI.FederatedEventHandler<PIXI.FederatedWheelEvent>;
121
- }
122
-
123
- interface ComponentInstance extends PixiMixins.ContainerOptions {
124
- id?: string;
125
- children?: ComponentInstance[];
126
- onInit?(props: Props): void;
127
- onUpdate?(props: Props): void;
128
- onDestroy?(parent: Element): void;
129
- onMount?(context: Element, index?: number): void;
130
- setWidth(width: number): void;
131
- setHeight(height: number): void;
132
- }
133
-
134
- interface Props {
135
- [key: string]: any;
136
- }
137
- type ArrayChange<T> = {
138
- type: "add" | "remove" | "update" | "init" | "reset";
139
- index?: number;
140
- items: T[];
141
- };
142
- type NestedSignalObjects = {
143
- [Key in string]: NestedSignalObjects | Signal<any>;
144
- };
145
- interface Element<T = ComponentInstance> {
146
- tag: string;
147
- props: Props;
148
- componentInstance: T;
149
- propSubscriptions: Subscription[];
150
- effectSubscriptions: Subscription[];
151
- effectMounts: (() => void)[];
152
- effectUnmounts: ((element?: Element) => void)[];
153
- propObservables: NestedSignalObjects | undefined;
154
- parent: Element | null;
155
- context?: {
156
- [key: string]: any;
157
- };
158
- directives: {
159
- [key: string]: Directive;
160
- };
161
- destroy: () => void;
162
- allElements: Subject<void>;
163
- }
164
- type FlowObservable = Observable<{
165
- elements: Element[];
166
- prev?: Element;
167
- }>;
168
- declare const isElement: (value: any) => value is Element;
169
- declare const isPrimitive: (value: any) => boolean;
170
- declare function registerComponent(name: any, component: any): void;
171
- /**
172
- * Creates a virtual element or a representation thereof, with properties that can be dynamically updated based on BehaviorSubjects.
173
- *
174
- * @param {string} tag - The tag name of the element to create.
175
- * @param {Object} props - An object containing properties for the element. Each property can either be a direct value
176
- * or an array where the first element is a function that returns a value based on input parameters,
177
- * and the second element is an array of BehaviorSubjects. The property is updated dynamically
178
- * using the combineLatest RxJS operator to wait for all BehaviorSubjects to emit.
179
- * @returns {Object} An object representing the created element, including tag name and dynamic properties.
180
- */
181
- declare function createComponent(tag: string, props?: Props): Element;
182
- /**
183
- * Observes a BehaviorSubject containing an array of items and dynamically creates child elements for each item.
184
- *
185
- * @param {BehaviorSubject<Array>} itemsSubject - A BehaviorSubject that emits an array of items.
186
- * @param {Function} createElementFn - A function that takes an item and returns an element representation.
187
- * @returns {Observable} An observable that emits the list of created child elements.
188
- */
189
- declare function loop<T = any>(itemsSubject: WritableArraySignal<T>, createElementFn: (item: any, index: number) => Element | Promise<Element>): FlowObservable;
190
- declare function cond(condition: Signal, createElementFn: () => Element | Promise<Element>): FlowObservable;
191
-
192
- declare abstract class Directive {
193
- abstract onDestroy(): any;
194
- abstract onInit(element: Element<any>): any;
195
- abstract onMount(element: Element<any>): any;
196
- abstract onUpdate(props: any): any;
197
- }
198
-
199
- interface Tick {
200
- timestamp: number;
201
- deltaTime: number;
202
- frame: number;
203
- deltaRatio: number;
204
- }
205
-
206
- type MountFunction = (fn: (element: Element) => void) => void;
207
- type ComponentFunction<P = {}> = (props: P) => Element | Promise<Element>;
208
- declare let currentSubscriptionsTracker: ((subscription: Subscription) => void) | null;
209
- declare let mountTracker: MountFunction | null;
210
- /**
211
- * Registers a mount function to be called when the component is mounted.
212
- * To unmount the component, the function must return a function that will be called by the engine.
213
- *
214
- * @param {(element: Element) => void} fn - The function to be called on mount.
215
- * @example
216
- * ```ts
217
- * mount((el) => {
218
- * console.log('mounted', el);
219
- * });
220
- * ```
221
- * Unmount the component by returning a function:
222
- * ```ts
223
- * mount((el) => {
224
- * console.log('mounted', el);
225
- * return () => {
226
- * console.log('unmounted', el);
227
- * }
228
- * });
229
- * ```
230
- */
231
- declare function mount(fn: (element: Element) => void): void;
232
- /**
233
- * Registers a tick function to be called on each tick of the component's context.
234
- * @param {(tickValue: Tick, element: Element) => void} fn - The function to be called on each tick.
235
- * @example
236
- * ```ts
237
- * tick((tickValue, el) => {
238
- * console.log('tick', tickValue, el);
239
- * });
240
- * ```
241
- */
242
- declare function tick(fn: (tickValue: Tick, element: Element) => void): void;
243
- /**
244
- * Add tracking for subscriptions and mounts, then create an element from a component function.
245
- * @template C
246
- * @param {C} componentFunction - The component function to create an element from.
247
- * @param {Parameters<C>[0]} [props={}] - The props to pass to the component function.
248
- * @param {...any[]} children - The children elements of the component.
249
- * @returns {ReturnType<C>}
250
- * @example
251
- * ```ts
252
- * const el = h(MyComponent, {
253
- * x: 100,
254
- * y: 100,
255
- * });
256
- * ```
257
- *
258
- * with children:
259
- * ```ts
260
- * const el = h(MyComponent, {
261
- * x: 100,
262
- * y: 100,
263
- * },
264
- * h(MyChildComponent, {
265
- * x: 50,
266
- * y: 50,
267
- * }),
268
- * );
269
- * ```
270
- */
271
- declare function h<C extends ComponentFunction<any>>(componentFunction: C, props?: Parameters<C>[0], ...children: any[]): ReturnType<C>;
272
-
273
- interface CanvasProps extends Props {
274
- cursorStyles?: () => any;
275
- width?: SignalOrPrimitive<Size>;
276
- height?: SignalOrPrimitive<Size>;
277
- canvasEl?: HTMLElement;
278
- selector?: string;
279
- isRoot?: boolean;
280
- tick?: any;
281
- class?: SignalOrPrimitive<string>;
282
- }
283
- declare const Canvas: ComponentFunction<CanvasProps>;
284
-
285
- interface ContainerProps extends DisplayObjectProps {
286
- sortableChildren?: boolean;
287
- }
288
- declare const Container: ComponentFunction<ContainerProps>;
289
-
290
- interface GraphicsProps extends DisplayObjectProps {
291
- draw?: (graphics: Graphics$1) => void;
292
- }
293
- interface RectProps extends DisplayObjectProps {
294
- width: number;
295
- height: number;
296
- color: string;
297
- }
298
- interface CircleProps extends DisplayObjectProps {
299
- radius: number;
300
- color: string;
301
- }
302
- interface EllipseProps extends DisplayObjectProps {
303
- width: number;
304
- height: number;
305
- color: string;
306
- }
307
- interface TriangleProps extends DisplayObjectProps {
308
- base: number;
309
- height: number;
310
- color: string;
311
- }
312
- interface SvgProps extends DisplayObjectProps {
313
- svg: string;
314
- }
315
- declare function Graphics(props: GraphicsProps): Element<ComponentInstance>;
316
- declare function Rect(props: RectProps): Element<ComponentInstance>;
317
- declare function Circle(props: CircleProps): Element<ComponentInstance>;
318
- declare function Ellipse(props: EllipseProps): Element<ComponentInstance>;
319
- declare function Triangle(props: TriangleProps): Element<ComponentInstance>;
320
- declare function Svg(props: SvgProps): Element<ComponentInstance>;
321
-
322
- declare function Scene(props: any): Element<ComponentInstance> | Promise<Element<ComponentInstance>>;
323
-
324
- declare function ParticlesEmitter(props: any): Element<ComponentInstance>;
325
-
326
- interface TransformOptions {
327
- /**
328
- * The global value of opacity (between 0 and 1)
329
- *
330
- * @prop {number} [opacity]
331
- * @memberof Spritesheet
332
- * */
333
- opacity?: number;
334
- /**
335
- * The global value of pivot.
336
- *
337
- * Invariant under rotation, scaling, and skewing. The projection of into the parent's space of the pivot is equal to position, regardless of the other three transformations. In other words, It is the center of rotation, scaling, and skewing.
338
- *
339
- * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
340
- *
341
- * ```ts
342
- * pivot: [0.5, 0.8]
343
- * ```
344
- *
345
- * @prop {Array<number>} [pivot]
346
- * @memberof Spritesheet
347
- * */
348
- pivot?: number[];
349
- /**
350
- * The global value of anchor.
351
- *
352
- * Position of the origin point
353
- *
354
- * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
355
- *
356
- * ```ts
357
- * anchor: [0.5, 0.8]
358
- * ```
359
- *
360
- * @prop {Array<number>} [anchor]
361
- * @memberof Spritesheet
362
- * */
363
- anchor?: number[];
364
- /**
365
- * Defines the actual size of the sprite that is inside a larger rectangle.
366
- * For example, if the texture rectangle is 192x192 while the character, which is in the center, is only 64x64 then set `spriteRealSize: 64`. This way the character will be well positioned in relation to the animations that have a different rectangle
367
- *
368
- * > You can also put `spriteRealSize: { width: 64, height: 64 }` but be aware that the width is not concerned because it will always be centered while the height depends on the hitbox
369
- *
370
- * @prop {{ width: number, height: number } | number} [spriteRealSize]
371
- * @since 3.2.0
372
- * @memberof Spritesheet
373
- * */
374
- spriteRealSize?: {
375
- width: number;
376
- height: number;
377
- } | number;
378
- /**
379
- * The global value of rotation
380
- *
381
- * Rotation. This will rotate the display object's projection by this angle (in radians).
382
- *
383
- * @prop {number} [angle]
384
- * @memberof Spritesheet
385
- * */
386
- angle?: number;
387
- /**
388
- * The global value of rotation
389
- *
390
- * Rotation. This is an alias for rotation, but in degrees.
391
- *
392
- * @prop {number} [rotation]
393
- * @memberof Spritesheet
394
- * */
395
- rotation?: number;
396
- /**
397
- * The global value of scale.
398
- *
399
- * Scaling. This will stretch (or compress) the display object's projection. The scale factors are along the local coordinate axes. In other words, the display object is scaled before rotated or skewed. The center of scaling is the pivot.
400
- *
401
- * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
402
- *
403
- * ```ts
404
- * scale: [0.5, 0.8]
405
- * ```
406
- *
407
- * @prop {Array<number>} [scale]
408
- * @memberof Spritesheet
409
- * */
410
- scale?: number[];
411
- /**
412
- * The global value of skew.
413
- *
414
- * Skewing. This can be used to deform a rectangular display object into a parallelogram.
415
- *
416
- * In PixiJS, skew has a slightly different behaviour than the conventional meaning. It can be thought of the net rotation applied to the coordinate axes (separately). For example, if "skew.x" is ⍺ and "skew.y" is β, then the line x = 0 will be rotated by ⍺ (y = -x*cot⍺) and the line y = 0 will be rotated by β (y = x*tanβ). A line y = x*tanϴ (i.e. a line at angle ϴ to the x-axis in local-space) will be rotated by an angle between ⍺ and β.
417
- *
418
- * It can be observed that if skew is applied equally to both axes, then it will be equivalent to applying a rotation. Indeed, if "skew.x" = -ϴ and "skew.y" = ϴ, it will produce an equivalent of "rotation" = ϴ.
419
- *
420
- * Another quite interesting observation is that "skew.x", "skew.y", rotation are communtative operations. Indeed, because rotation is essentially a careful combination of the two.
421
- *
422
- * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
423
- *
424
- * @prop {Array<number>} [skew]
425
- * @memberof Spritesheet
426
- * */
427
- skew?: number[];
428
- /**
429
- * The global value of X translation
430
- *
431
- * @prop {number} [x]
432
- * @memberof Spritesheet
433
- * */
434
- x?: number;
435
- /**
436
- * The global value of Y translation
437
- *
438
- * @prop {number} [y]
439
- * @memberof Spritesheet
440
- * */
441
- y?: number;
442
- /**
443
- * The global value of visible
444
- *
445
- * @prop {boolean} [visible]
446
- * @memberof Spritesheet
447
- * */
448
- visible?: boolean;
449
- /**
450
- * Define the sound that will be played for all animations in the spritesheet. Remember to create the sound before with the @Sound decorator
451
- *
452
- * @prop {string} [sound]
453
- * @memberof Spritesheet
454
- * */
455
- sound?: string;
456
- }
457
- interface FrameOptions extends TransformOptions {
458
- time: number;
459
- frameX?: number;
460
- frameY?: number;
461
- }
462
- interface TextureOptions {
463
- /**
464
- * The number of frames on the width
465
- *
466
- * @prop {number} framesWidth
467
- * @memberof Spritesheet
468
- * */
469
- framesWidth?: number;
470
- /**
471
- * The number of frames on the height
472
- *
473
- * @prop {number} framesHeight
474
- * @memberof Spritesheet
475
- * */
476
- framesHeight?: number;
477
- /**
478
- * The width of the image (in pixels)
479
- *
480
- * @prop {number} width
481
- * @memberof Spritesheet
482
- * */
483
- width?: number;
484
- /**
485
- * The height of the image (in pixels)
486
- *
487
- * @prop {number} height
488
- * @memberof Spritesheet
489
- * */
490
- height?: number;
491
- /**
492
- * Takes a width of a rectangle in the image. Equivalent to `width / framesWidth`
493
- *
494
- * @prop {number} [rectWidth]
495
- * @memberof Spritesheet
496
- * */
497
- rectWidth?: number;
498
- /**
499
- * Takes a height of a rectangle in the image. Equivalent to `height / framesHeight`
500
- *
501
- * @prop {number} [rectHeight]
502
- * @memberof Spritesheet
503
- * */
504
- rectHeight?: number;
505
- /**
506
- * To take the texture, start at a well defined X and Y position. Otherwise, it starts at 0,0
507
- *
508
- * @prop {number} [offset]
509
- * @memberof Spritesheet
510
- * */
511
- offset?: {
512
- x: number;
513
- y: number;
514
- };
515
- }
516
- type AnimationFrames = FrameOptions[][] | ((...args: any) => FrameOptions[][]);
517
- interface TexturesOptions extends TextureOptions, TransformOptions {
518
- animations: AnimationFrames;
519
- }
520
- interface SpritesheetOptions extends TransformOptions, TextureOptions {
521
- /**
522
- * Object containing all animations.
523
- * The key to the object is the name of the animation. The value is a two-dimensional array
524
- *
525
- * ```ts
526
- * textures: {
527
- * myanim: {
528
- * animations: [
529
- * [ { time: 0, frameX: 0, frameY: 0 } ]
530
- * ]
531
- * }
532
- * }
533
- * ```
534
- *
535
- * The first array represents an animation group. You can put several of them together to create an animation cluster. For example, several explosions with the same spritesheet
536
- * The second array represents the animation itself which will animate over time. The object indicates, over a period of time (in frame), which part of the spritesheet will be taken (`frameX`, `frameY`)
537
- *
538
- * Here are the properties:
539
- *
540
- * * `time`: Time in frame
541
- * * `frameX`: Retrieve a frame from the spritesheet on the X-axis
542
- * * `frameY`: Retrieve a frame from the spritesheet on the Y-axis
543
- * * `opacity`
544
- * * `pivot`
545
- * * `anchor`
546
- * * `rotation`
547
- * * `angle`
548
- * * `scale`
549
- * * `skew`
550
- * * `x`
551
- * * `y`
552
- * * `visible`
553
- * * `sound`: The sound that will be played during the frame
554
- *
555
- * ---
556
- * **Extract Animation of Spritesheet**
557
- *
558
- * Sometimes the animation is part of the image
559
- *
560
- * ```ts
561
- * textures: {
562
- * myanim: {
563
- * rectWidth: 64,
564
- * rectHeight: 64,
565
- * framesWidth: 10,
566
- * framesHeight: 2,
567
- * offset: {x: 0, y: 230},
568
- * sound: 'my-sound-id', // You can put a sound just for the animation
569
- * animations: [
570
- * [ { time: 0, frameX: 0, frameY: 0 } ]
571
- * ]
572
- * }
573
- * }
574
- * ```
575
- *
576
- * Above, we can specify which part we want to recover
577
- *
578
- * 1. We go to the position {0, 230} of the image (`offset`)
579
- * 2. We recover cells of 64px (`rectWidth` and `rectHeight`)
580
- * 3. And we get 20 cells (10 on the width, 2 on the height) (`frameX` and `frameY`)
581
- *
582
- * ---
583
- *
584
- * **Advanced**
585
- *
586
- * You can create an animation that will be linked to a data. For example, different animation according to a direction of the character.
587
- *
588
- * Full example:
589
- *
590
- * ```ts
591
- * import { Spritesheet, Animation, Direction } from '@rpgjs/client'
592
- *
593
- * @Spritesheet({
594
- * id: 'chest',
595
- * image: require('./assets/chest.png'),
596
- * width: 124,
597
- * height: 61,
598
- * framesHeight: 2,
599
- * framesWidth: 4,
600
- * textures: {
601
- * [Animation.Stand]: {
602
- * animations: direction => [[ {time: 0, frameX: 3, frameY: direction == Direction.Up ? 0 : 1 } ]]
603
- * }
604
- * })
605
- * })
606
- * export class Chest { }
607
- * ```
608
- *
609
- * > It is important to know that `Animation.Stand` animation is called if it exists. it only works in the case of an event that doesn't move. The direction is then sent
610
- *
611
- * As you can see, the property contains a function that returns the array for the animation. Here, it is the direction but the parameters depend on the call of the animation. Example:
612
- *
613
- * ```ts
614
- * import { Spritesheet, Animation, Direction, RpgSprite, ISpriteCharacter } from '@rpgjs/client'
615
- *
616
- * @Spritesheet({
617
- * id: 'chest',
618
- * image: require('./assets/chest.png'),
619
- * width: 124,
620
- * height: 61,
621
- * framesHeight: 2,
622
- * framesWidth: 4,
623
- * textures: {
624
- * [Animation.Stand]: {
625
- * animations: str => [[ {time: 0, frameX: 3, frameY: str == 'hello' ? 0 : 1 } ]]
626
- * }
627
- * }
628
- * })
629
- * export class Chest implements ISpriteCharacter {
630
- * onCharacterStand(sprite: RpgSprite) {
631
- * sprite.animation.play(Animation.Stand, ['hello'])
632
- * }
633
- * }
634
- * ```
635
- *
636
- * @prop { { [animName: string]: { animations: Array<Array<FrameOptions>> | Function, ...other } } } [textures]
637
- * @memberof Spritesheet
638
- * */
639
- textures?: {
640
- [animationName: string]: Partial<TexturesOptions> & Pick<TexturesOptions, 'animations'>;
641
- };
642
- }
643
-
644
- type Image = {
645
- image: string;
646
- };
647
- type TextureOptionsMerging = TextureOptions & {
648
- spriteWidth: number;
649
- spriteHeight: number;
650
- sound?: string;
651
- } & Image & TransformOptions;
652
- type SpritesheetOptionsMerging = TextureOptionsMerging & SpritesheetOptions;
653
- interface SpriteProps extends DisplayObjectProps {
654
- sheet?: {
655
- definition?: SpritesheetOptionsMerging;
656
- playing?: string;
657
- params?: any;
658
- onFinish?: () => void;
659
- };
660
- scaleMode?: number;
661
- image?: string;
662
- rectangle?: {
663
- x: number;
664
- y: number;
665
- width: number;
666
- height: number;
667
- };
668
- context?: {
669
- tick: Signal;
670
- };
671
- }
672
- interface SpritePropsWithImage extends Omit<SpriteProps, "sheet"> {
673
- image: string;
674
- rectangle?: {
675
- x: number;
676
- y: number;
677
- width: number;
678
- height: number;
679
- };
680
- }
681
- interface SpritePropsWithSheet extends Omit<SpriteProps, "image" | "rectangle"> {
682
- sheet: {
683
- definition: SpritesheetOptionsMerging;
684
- playing?: string;
685
- params?: any;
686
- onFinish?: () => void;
687
- };
688
- }
689
- type SpritePropTypes = SpritePropsWithImage | SpritePropsWithSheet;
690
- declare const Sprite: ComponentFunction<SpritePropTypes>;
691
-
692
- interface TextProps extends DisplayObjectProps {
693
- text?: string;
694
- style?: Partial<TextStyle>;
695
- color?: string;
696
- size?: string;
697
- fontFamily?: string;
698
- typewriter?: {
699
- speed?: number;
700
- start?: () => void;
701
- onComplete?: () => void;
702
- skip?: () => void;
703
- };
704
- }
705
- declare function Text(props: TextProps): Element<ComponentInstance>;
706
-
707
- declare function TiledMap(props: any): any;
708
-
709
- interface TilingSpriteProps extends DisplayObjectProps {
710
- image?: string;
711
- tileScale?: {
712
- x: number;
713
- y: number;
714
- };
715
- tilePosition?: {
716
- x: number;
717
- y: number;
718
- };
719
- width?: number;
720
- height?: number;
721
- }
722
- declare function TilingSprite(props: TilingSpriteProps): Element<ComponentInstance>;
723
-
724
- interface ViewportProps {
725
- screenWidth?: number;
726
- screenHeight?: number;
727
- worldWidth?: number;
728
- worldHeight?: number;
729
- clamp?: boolean | {
730
- left?: number;
731
- right?: number;
732
- top?: number;
733
- bottom?: number;
734
- };
735
- [key: string]: any;
736
- }
737
- declare function Viewport(props: ViewportProps): Element<ComponentInstance>;
738
-
739
- declare function ImageMap(props: any): Element<ComponentInstance> | Promise<Element<ComponentInstance>>;
740
-
741
- interface NineSliceSpriteProps extends DisplayObjectProps {
742
- image?: string;
743
- texture?: Texture;
744
- width?: number;
745
- height?: number;
746
- leftWidth?: number;
747
- rightWidth?: number;
748
- topHeight?: number;
749
- bottomHeight?: number;
750
- roundPixels?: boolean;
751
- }
752
- declare function NineSliceSprite(props: NineSliceSpriteProps): Element<ComponentInstance>;
753
-
754
- interface Listen<T = any> {
755
- config: T | undefined;
756
- seed: number;
757
- }
758
- interface Trigger<T = any> {
759
- start: () => void;
760
- listen: () => Listen<T> | undefined;
761
- }
762
- declare function isTrigger(arg: any): arg is Trigger<any>;
763
- declare function trigger<T = any>(config?: T): Trigger<T>;
764
- declare function on(triggerSignal: any, callback: (config: any) => void): void;
765
-
766
- /**
767
- * Bootstraps a canvas element and renders it to the DOM.
768
- *
769
- * @param rootElement - The HTML element where the canvas will be rendered. Can be null.
770
- * @param canvas - A Promise that resolves to an Element representing the canvas component.
771
- * @returns A Promise that resolves to the rendered canvas element.
772
- * @throws {Error} If the provided element is not a Canvas component.
773
- */
774
- declare const bootstrapCanvas: (rootElement: HTMLElement | null, canvas: ComponentFunction<any>) => Promise<Element<ComponentInstance>>;
775
-
776
- /**
777
- * Converts props into reactive signals if they are primitive values.
778
- *
779
- * @param {object} props - The properties to convert.
780
- * @param {object} [defaults={}] - Default values for properties.
781
- * @returns {object} An object with reactive signals.
782
- *
783
- * @example
784
- * const props = useProps({ count: 0, name: "John" });
785
- * console.log(props.count()); // 0
786
- * props.count.set(1);
787
- * console.log(props.count()); // 1
788
- */
789
- declare const useProps: (props: any, defaults?: {}) => any;
790
- type PropType = NumberConstructor | StringConstructor | BooleanConstructor | FunctionConstructor | ObjectConstructor | ArrayConstructor | null | (new (...args: any[]) => any);
791
- interface PropConfig {
792
- type?: PropType | PropType[];
793
- required?: boolean;
794
- default?: any | ((props: any) => any);
795
- validator?: (value: any, props: any) => boolean;
796
- }
797
- type PropSchema = {
798
- [key: string]: PropType | PropType[] | PropConfig;
799
- };
800
- /**
801
- * Validates and defines properties based on a schema.
802
- *
803
- * @param {object} props - The properties to validate.
804
- * @returns {function} A function that takes a schema and returns validated properties.
805
- *
806
- * @example
807
- * const schema = {
808
- * age: { type: Number, required: true },
809
- * name: { type: String, default: "Anonymous" }
810
- * };
811
- * const validatedProps = useDefineProps({ age: 25 })(schema);
812
- * console.log(validatedProps.age()); // 25
813
- * console.log(validatedProps.name()); // "Anonymous"
814
- */
815
- declare const useDefineProps: (props: any) => (schema?: PropSchema) => any;
816
-
817
- interface BarProps {
818
- backgroundColor?: string;
819
- foregroundColor?: string;
820
- value: number;
821
- maxValue: number;
822
- width: number;
823
- height: number;
824
- }
825
- declare function Bar(opts: BarProps): Element<ComponentInstance>;
826
-
827
- declare function Particle(options: any): Element<ComponentInstance> | Promise<Element<ComponentInstance>>;
828
-
829
- declare const Easing: {
830
- linear: popmotion.Easing;
831
- easeIn: popmotion.Easing;
832
- easeInOut: popmotion.Easing;
833
- easeOut: popmotion.Easing;
834
- circIn: popmotion.Easing;
835
- circInOut: popmotion.Easing;
836
- circOut: popmotion.Easing;
837
- backIn: popmotion.Easing;
838
- backInOut: popmotion.Easing;
839
- backOut: popmotion.Easing;
840
- anticipate: popmotion.Easing;
841
- bounceIn: popmotion.Easing;
842
- bounceInOut: (p: number) => number;
843
- bounceOut: (p: number) => number;
844
- };
845
-
846
- export { type AnimatedSignal, type AnimatedState, type ArrayChange, Bar, Canvas, Circle, type ComponentFunction, Container, Easing, type Element, Ellipse, Graphics, ImageMap, NineSliceSprite, Particle, ParticlesEmitter, type Props, Rect, Scene, Sprite, Text, TiledMap, 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 };