canvasengine 2.0.0-beta.7 → 2.0.0-beta.8
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 +23 -3
- package/dist/index.js +37 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DisplayObject.ts +3 -3
- package/src/components/Text.ts +2 -2
- package/src/engine/animation.ts +41 -5
- package/src/engine/reactive.ts +1 -2
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface AnimateOptions<T> {
|
|
|
13
13
|
duration?: number;
|
|
14
14
|
ease?: (t: number) => number;
|
|
15
15
|
onUpdate?: (value: T) => void;
|
|
16
|
+
onComplete?: () => void;
|
|
16
17
|
}
|
|
17
18
|
interface AnimatedState<T> {
|
|
18
19
|
current: T;
|
|
@@ -21,7 +22,7 @@ interface AnimatedState<T> {
|
|
|
21
22
|
}
|
|
22
23
|
interface AnimatedSignal<T> extends Omit<WritableSignal<T>, 'set'> {
|
|
23
24
|
(): T;
|
|
24
|
-
set: (newValue: T) => void
|
|
25
|
+
set: (newValue: T, options?: AnimateOptions<T>) => Promise<void>;
|
|
25
26
|
animatedState: WritableSignal<AnimatedState<T>>;
|
|
26
27
|
update: (updater: (value: T) => T) => void;
|
|
27
28
|
}
|
|
@@ -45,6 +46,25 @@ declare function isAnimatedSignal(signal: WritableSignal<any>): boolean;
|
|
|
45
46
|
* animatedValue.animatedState() // { current: 10, start: 10, end: 11 }
|
|
46
47
|
*/
|
|
47
48
|
declare function animatedSignal<T>(initialValue: T, options?: AnimateOptions<T>): AnimatedSignal<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Executes a sequence of animations. If an array is provided as an element in the sequence,
|
|
51
|
+
* those animations will be executed in parallel.
|
|
52
|
+
*
|
|
53
|
+
* @param sequence Array of animation functions or arrays of animation functions for parallel execution
|
|
54
|
+
* @returns Promise that resolves when all animations are complete
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* await animatedSequence([
|
|
58
|
+
* () => value1.set(10),
|
|
59
|
+
* [
|
|
60
|
+
* () => value2.set(20),
|
|
61
|
+
* () => value3.set(30)
|
|
62
|
+
* ],
|
|
63
|
+
* () => value1.set(0)
|
|
64
|
+
* ])
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function animatedSequence(sequence: ((() => Promise<void>) | (() => Promise<void>)[])[]): Promise<void>;
|
|
48
68
|
|
|
49
69
|
type SignalOrPrimitive<T> = T | Signal<T> | AnimatedSignal<T>;
|
|
50
70
|
|
|
@@ -157,7 +177,7 @@ declare function DisplayObject(extendClass: any): {
|
|
|
157
177
|
onInit(props: any): void;
|
|
158
178
|
onMount({ parent, props }: Element</*elided*/ any>, index?: number): void;
|
|
159
179
|
effectSize(width: Size, height: Size): void;
|
|
160
|
-
|
|
180
|
+
applyFlexLayout(): void;
|
|
161
181
|
"__#1@#flexRender"(props: any): void;
|
|
162
182
|
onUpdate(props: any): void;
|
|
163
183
|
onDestroy(): void;
|
|
@@ -1114,4 +1134,4 @@ declare namespace utils {
|
|
|
1114
1134
|
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 };
|
|
1115
1135
|
}
|
|
1116
1136
|
|
|
1117
|
-
export { type AnimatedSignal, type AnimatedState, type ArrayChange, Canvas, Circle, type ComponentFunction, type ComponentInstance, Container, DisplayObject, EVENTS, Easing, type Element, Ellipse, Graphics, NineSliceSprite, type ObjectChange, 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 };
|
|
1137
|
+
export { type AnimateOptions, type AnimatedSignal, type AnimatedState, type ArrayChange, Canvas, Circle, type ComponentFunction, type ComponentInstance, Container, DisplayObject, EVENTS, Easing, type Element, Ellipse, Graphics, NineSliceSprite, type ObjectChange, ParticlesEmitter, type Props, RadialGradient, Rect, Scene, Sprite, Text, TilingSprite, Triangle, utils as Utils, Video, Viewport, animatedSequence, animatedSignal, bootstrapCanvas, cond, createComponent, currentSubscriptionsTracker, h, isAnimatedSignal, isElement, isPrimitive, isTrigger, loop, mount, mountTracker, on, registerComponent, Svg as svg, tick, trigger, useDefineProps, useProps };
|
package/dist/index.js
CHANGED
|
@@ -1308,9 +1308,9 @@ function createComponent(tag, props) {
|
|
|
1308
1308
|
function loop(itemsSubject, createElementFn) {
|
|
1309
1309
|
let elements = [];
|
|
1310
1310
|
const isArraySignal = "_subject" in itemsSubject && "items" in itemsSubject._subject;
|
|
1311
|
-
const addAt = (
|
|
1312
|
-
return
|
|
1313
|
-
const key =
|
|
1311
|
+
const addAt = (items, insertIndex, keys) => {
|
|
1312
|
+
return items.map((item, index) => {
|
|
1313
|
+
const key = keys ? keys[index] : typeof insertIndex === "number" ? insertIndex + index : insertIndex;
|
|
1314
1314
|
const element = createElementFn(item, key);
|
|
1315
1315
|
if (typeof insertIndex === "number") {
|
|
1316
1316
|
elements.splice(insertIndex + index, 0, element);
|
|
@@ -1334,8 +1334,8 @@ function loop(itemsSubject, createElementFn) {
|
|
|
1334
1334
|
};
|
|
1335
1335
|
}
|
|
1336
1336
|
};
|
|
1337
|
-
const { items, keys } = getInitialItems();
|
|
1338
1337
|
return defer(() => {
|
|
1338
|
+
const { items, keys } = getInitialItems();
|
|
1339
1339
|
let initialItems = [...items];
|
|
1340
1340
|
let initialKeys = keys ? [...keys] : void 0;
|
|
1341
1341
|
let init = true;
|
|
@@ -1638,7 +1638,7 @@ var EVENTS2 = [
|
|
|
1638
1638
|
"wheelcapture"
|
|
1639
1639
|
];
|
|
1640
1640
|
function DisplayObject(extendClass) {
|
|
1641
|
-
var _canvasContext, _DisplayObject_instances,
|
|
1641
|
+
var _canvasContext, _DisplayObject_instances, flexRender_fn, setAlign_fn, setEdgeSize_fn, _a;
|
|
1642
1642
|
return _a = class extends extendClass {
|
|
1643
1643
|
constructor() {
|
|
1644
1644
|
super(...arguments);
|
|
@@ -1707,7 +1707,7 @@ function DisplayObject(extendClass) {
|
|
|
1707
1707
|
effect3(() => {
|
|
1708
1708
|
setter(parentSize() * (parseInt(size) / 100));
|
|
1709
1709
|
if (this.isFlex) {
|
|
1710
|
-
|
|
1710
|
+
this.applyFlexLayout();
|
|
1711
1711
|
}
|
|
1712
1712
|
});
|
|
1713
1713
|
} else {
|
|
@@ -1723,6 +1723,14 @@ function DisplayObject(extendClass) {
|
|
|
1723
1723
|
this.parent.displayHeight
|
|
1724
1724
|
);
|
|
1725
1725
|
}
|
|
1726
|
+
applyFlexLayout() {
|
|
1727
|
+
this.calculateLayout();
|
|
1728
|
+
for (let child of this.children) {
|
|
1729
|
+
const { left, top } = child.node.getComputedLayout();
|
|
1730
|
+
child.x = left;
|
|
1731
|
+
child.y = top;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1726
1734
|
onUpdate(props) {
|
|
1727
1735
|
this.fullProps = {
|
|
1728
1736
|
...this.fullProps,
|
|
@@ -1900,18 +1908,11 @@ function DisplayObject(extendClass) {
|
|
|
1900
1908
|
getHeight() {
|
|
1901
1909
|
return this.displayHeight();
|
|
1902
1910
|
}
|
|
1903
|
-
}, _canvasContext = new WeakMap(), _DisplayObject_instances = new WeakSet(),
|
|
1904
|
-
this.calculateLayout();
|
|
1905
|
-
for (let child of this.children) {
|
|
1906
|
-
const { left, top } = child.node.getComputedLayout();
|
|
1907
|
-
child.x = left;
|
|
1908
|
-
child.y = top;
|
|
1909
|
-
}
|
|
1910
|
-
}, flexRender_fn = function(props) {
|
|
1911
|
+
}, _canvasContext = new WeakMap(), _DisplayObject_instances = new WeakSet(), flexRender_fn = function(props) {
|
|
1911
1912
|
if (!this.parent) return;
|
|
1912
1913
|
if (props.flexDirection || props.justifyContent) {
|
|
1913
1914
|
this.isFlex = true;
|
|
1914
|
-
|
|
1915
|
+
this.applyFlexLayout();
|
|
1915
1916
|
}
|
|
1916
1917
|
}, setAlign_fn = function(methodName, align) {
|
|
1917
1918
|
const mapping = {
|
|
@@ -2277,7 +2278,7 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2277
2278
|
const currentState = privateSignal();
|
|
2278
2279
|
publicSignal.set(currentState.current);
|
|
2279
2280
|
});
|
|
2280
|
-
function animatedSignal2(newValue) {
|
|
2281
|
+
function animatedSignal2(newValue, animationConfig = {}) {
|
|
2281
2282
|
if (newValue === void 0) {
|
|
2282
2283
|
return privateSignal();
|
|
2283
2284
|
}
|
|
@@ -2295,6 +2296,7 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2295
2296
|
// TODO
|
|
2296
2297
|
duration: 20,
|
|
2297
2298
|
...options,
|
|
2299
|
+
...animationConfig,
|
|
2298
2300
|
from: prevState.current,
|
|
2299
2301
|
to: newValue,
|
|
2300
2302
|
onUpdate: (value) => {
|
|
@@ -2315,11 +2317,25 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2315
2317
|
fn.update = (updater) => {
|
|
2316
2318
|
animatedSignal2(updater(privateSignal().current));
|
|
2317
2319
|
};
|
|
2318
|
-
fn.set = (newValue) => {
|
|
2319
|
-
|
|
2320
|
+
fn.set = async (newValue, animationConfig = {}) => {
|
|
2321
|
+
return new Promise((resolve) => {
|
|
2322
|
+
animatedSignal2(newValue, {
|
|
2323
|
+
...animationConfig,
|
|
2324
|
+
onComplete: resolve
|
|
2325
|
+
});
|
|
2326
|
+
});
|
|
2320
2327
|
};
|
|
2321
2328
|
return fn;
|
|
2322
2329
|
}
|
|
2330
|
+
async function animatedSequence(sequence) {
|
|
2331
|
+
for (const item of sequence) {
|
|
2332
|
+
if (Array.isArray(item)) {
|
|
2333
|
+
await Promise.all(item.map((fn) => fn()));
|
|
2334
|
+
} else {
|
|
2335
|
+
await item();
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2323
2339
|
|
|
2324
2340
|
// src/components/Sprite.ts
|
|
2325
2341
|
var log2 = console.log;
|
|
@@ -2821,8 +2837,8 @@ var CanvasText = class extends DisplayObject(PixiText) {
|
|
|
2821
2837
|
this.typewriterOptions = props.typewriter;
|
|
2822
2838
|
}
|
|
2823
2839
|
}
|
|
2824
|
-
if (props.text) {
|
|
2825
|
-
this.text = props.text;
|
|
2840
|
+
if (props.text !== void 0) {
|
|
2841
|
+
this.text = "" + props.text;
|
|
2826
2842
|
}
|
|
2827
2843
|
if (props.text !== void 0 && props.text !== this.fullText && this.fullProps.typewriter) {
|
|
2828
2844
|
this.text = "";
|
|
@@ -3218,6 +3234,7 @@ export {
|
|
|
3218
3234
|
utils_exports as Utils,
|
|
3219
3235
|
Video,
|
|
3220
3236
|
Viewport,
|
|
3237
|
+
animatedSequence,
|
|
3221
3238
|
animatedSignal,
|
|
3222
3239
|
bootstrapCanvas,
|
|
3223
3240
|
cond,
|