canvasengine 2.0.0-beta.7 → 2.0.0-beta.9
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 +39 -21
- 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 +3 -4
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;
|
|
@@ -1343,7 +1343,7 @@ function loop(itemsSubject, createElementFn) {
|
|
|
1343
1343
|
map((event) => {
|
|
1344
1344
|
const { type, items: items2 } = event;
|
|
1345
1345
|
const index = "index" in event ? event.index : event.key;
|
|
1346
|
-
if (init) {
|
|
1346
|
+
if (init && type != "add") {
|
|
1347
1347
|
if (elements.length > 0) {
|
|
1348
1348
|
return {
|
|
1349
1349
|
elements,
|
|
@@ -1396,6 +1396,7 @@ function loop(itemsSubject, createElementFn) {
|
|
|
1396
1396
|
} else {
|
|
1397
1397
|
newElements = addAt(items2, index);
|
|
1398
1398
|
}
|
|
1399
|
+
init = false;
|
|
1399
1400
|
return {
|
|
1400
1401
|
prev: lastElement,
|
|
1401
1402
|
elements: newElements,
|
|
@@ -1638,7 +1639,7 @@ var EVENTS2 = [
|
|
|
1638
1639
|
"wheelcapture"
|
|
1639
1640
|
];
|
|
1640
1641
|
function DisplayObject(extendClass) {
|
|
1641
|
-
var _canvasContext, _DisplayObject_instances,
|
|
1642
|
+
var _canvasContext, _DisplayObject_instances, flexRender_fn, setAlign_fn, setEdgeSize_fn, _a;
|
|
1642
1643
|
return _a = class extends extendClass {
|
|
1643
1644
|
constructor() {
|
|
1644
1645
|
super(...arguments);
|
|
@@ -1707,7 +1708,7 @@ function DisplayObject(extendClass) {
|
|
|
1707
1708
|
effect3(() => {
|
|
1708
1709
|
setter(parentSize() * (parseInt(size) / 100));
|
|
1709
1710
|
if (this.isFlex) {
|
|
1710
|
-
|
|
1711
|
+
this.applyFlexLayout();
|
|
1711
1712
|
}
|
|
1712
1713
|
});
|
|
1713
1714
|
} else {
|
|
@@ -1723,6 +1724,14 @@ function DisplayObject(extendClass) {
|
|
|
1723
1724
|
this.parent.displayHeight
|
|
1724
1725
|
);
|
|
1725
1726
|
}
|
|
1727
|
+
applyFlexLayout() {
|
|
1728
|
+
this.calculateLayout();
|
|
1729
|
+
for (let child of this.children) {
|
|
1730
|
+
const { left, top } = child.node.getComputedLayout();
|
|
1731
|
+
child.x = left;
|
|
1732
|
+
child.y = top;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1726
1735
|
onUpdate(props) {
|
|
1727
1736
|
this.fullProps = {
|
|
1728
1737
|
...this.fullProps,
|
|
@@ -1900,18 +1909,11 @@ function DisplayObject(extendClass) {
|
|
|
1900
1909
|
getHeight() {
|
|
1901
1910
|
return this.displayHeight();
|
|
1902
1911
|
}
|
|
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) {
|
|
1912
|
+
}, _canvasContext = new WeakMap(), _DisplayObject_instances = new WeakSet(), flexRender_fn = function(props) {
|
|
1911
1913
|
if (!this.parent) return;
|
|
1912
1914
|
if (props.flexDirection || props.justifyContent) {
|
|
1913
1915
|
this.isFlex = true;
|
|
1914
|
-
|
|
1916
|
+
this.applyFlexLayout();
|
|
1915
1917
|
}
|
|
1916
1918
|
}, setAlign_fn = function(methodName, align) {
|
|
1917
1919
|
const mapping = {
|
|
@@ -2277,7 +2279,7 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2277
2279
|
const currentState = privateSignal();
|
|
2278
2280
|
publicSignal.set(currentState.current);
|
|
2279
2281
|
});
|
|
2280
|
-
function animatedSignal2(newValue) {
|
|
2282
|
+
function animatedSignal2(newValue, animationConfig = {}) {
|
|
2281
2283
|
if (newValue === void 0) {
|
|
2282
2284
|
return privateSignal();
|
|
2283
2285
|
}
|
|
@@ -2295,6 +2297,7 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2295
2297
|
// TODO
|
|
2296
2298
|
duration: 20,
|
|
2297
2299
|
...options,
|
|
2300
|
+
...animationConfig,
|
|
2298
2301
|
from: prevState.current,
|
|
2299
2302
|
to: newValue,
|
|
2300
2303
|
onUpdate: (value) => {
|
|
@@ -2315,11 +2318,25 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2315
2318
|
fn.update = (updater) => {
|
|
2316
2319
|
animatedSignal2(updater(privateSignal().current));
|
|
2317
2320
|
};
|
|
2318
|
-
fn.set = (newValue) => {
|
|
2319
|
-
|
|
2321
|
+
fn.set = async (newValue, animationConfig = {}) => {
|
|
2322
|
+
return new Promise((resolve) => {
|
|
2323
|
+
animatedSignal2(newValue, {
|
|
2324
|
+
...animationConfig,
|
|
2325
|
+
onComplete: resolve
|
|
2326
|
+
});
|
|
2327
|
+
});
|
|
2320
2328
|
};
|
|
2321
2329
|
return fn;
|
|
2322
2330
|
}
|
|
2331
|
+
async function animatedSequence(sequence) {
|
|
2332
|
+
for (const item of sequence) {
|
|
2333
|
+
if (Array.isArray(item)) {
|
|
2334
|
+
await Promise.all(item.map((fn) => fn()));
|
|
2335
|
+
} else {
|
|
2336
|
+
await item();
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2323
2340
|
|
|
2324
2341
|
// src/components/Sprite.ts
|
|
2325
2342
|
var log2 = console.log;
|
|
@@ -2821,8 +2838,8 @@ var CanvasText = class extends DisplayObject(PixiText) {
|
|
|
2821
2838
|
this.typewriterOptions = props.typewriter;
|
|
2822
2839
|
}
|
|
2823
2840
|
}
|
|
2824
|
-
if (props.text) {
|
|
2825
|
-
this.text = props.text;
|
|
2841
|
+
if (props.text !== void 0) {
|
|
2842
|
+
this.text = "" + props.text;
|
|
2826
2843
|
}
|
|
2827
2844
|
if (props.text !== void 0 && props.text !== this.fullText && this.fullProps.typewriter) {
|
|
2828
2845
|
this.text = "";
|
|
@@ -3218,6 +3235,7 @@ export {
|
|
|
3218
3235
|
utils_exports as Utils,
|
|
3219
3236
|
Video,
|
|
3220
3237
|
Viewport,
|
|
3238
|
+
animatedSequence,
|
|
3221
3239
|
animatedSignal,
|
|
3222
3240
|
bootstrapCanvas,
|
|
3223
3241
|
cond,
|