canvasengine 2.0.0-beta.11 → 2.0.0-beta.13
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 +2 -2
- package/dist/index.js +327 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Viewport.ts +6 -12
- package/src/directives/Drag.ts +251 -53
- package/src/directives/KeyboardControls.ts +3 -1
- package/src/directives/ViewportFollow.ts +12 -6
- package/src/engine/directive.ts +2 -2
- package/src/engine/reactive.ts +2 -2
- package/src/hooks/useProps.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -290,10 +290,10 @@ declare function loop<T>(itemsSubject: WritableArraySignal<T[]> | WritableObject
|
|
|
290
290
|
declare function cond(condition: Signal<boolean> | boolean, createElementFn: () => Element | Promise<Element>): FlowObservable;
|
|
291
291
|
|
|
292
292
|
declare abstract class Directive {
|
|
293
|
-
abstract onDestroy(): any;
|
|
293
|
+
abstract onDestroy(element: Element<any>): any;
|
|
294
294
|
abstract onInit(element: Element<any>): any;
|
|
295
295
|
abstract onMount(element: Element<any>): any;
|
|
296
|
-
abstract onUpdate(props: any): any;
|
|
296
|
+
abstract onUpdate(props: any, element: Element<any>): any;
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
interface Tick {
|
package/dist/index.js
CHANGED
|
@@ -347,8 +347,10 @@ var KeyboardControls = class extends Directive {
|
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
349
|
onInit(element) {
|
|
350
|
+
const value = element.props.controls.value ?? element.props.controls;
|
|
351
|
+
if (!value) return;
|
|
350
352
|
this.setupListeners();
|
|
351
|
-
this.setInputs(
|
|
353
|
+
this.setInputs(value);
|
|
352
354
|
this.interval = setInterval(() => {
|
|
353
355
|
this.preStep();
|
|
354
356
|
}, fps2ms(this.serverFps ?? 60));
|
|
@@ -962,16 +964,24 @@ var ViewportFollow = class extends Directive {
|
|
|
962
964
|
onInit(element) {
|
|
963
965
|
}
|
|
964
966
|
onMount(element) {
|
|
967
|
+
this.onUpdate(element.props, element);
|
|
968
|
+
}
|
|
969
|
+
onUpdate(props, element) {
|
|
965
970
|
const { viewportFollow } = element.props;
|
|
966
971
|
const { viewport } = element.props.context;
|
|
967
972
|
if (!viewport) {
|
|
968
973
|
throw error("ViewportFollow directive requires a Viewport component to be mounted in the same context");
|
|
969
974
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
975
|
+
if (viewportFollow) {
|
|
976
|
+
viewport.follow(element.componentInstance);
|
|
977
|
+
} else {
|
|
978
|
+
viewport.plugins.remove("follow");
|
|
979
|
+
}
|
|
973
980
|
}
|
|
974
|
-
onDestroy() {
|
|
981
|
+
onDestroy(element) {
|
|
982
|
+
const { viewportFollow } = element.props;
|
|
983
|
+
const { viewport } = element.props.context;
|
|
984
|
+
if (viewportFollow) viewport.plugins.remove("follow");
|
|
975
985
|
}
|
|
976
986
|
};
|
|
977
987
|
registerDirective("viewportFollow", ViewportFollow);
|
|
@@ -1061,54 +1071,23 @@ registerDirective("sound", Sound);
|
|
|
1061
1071
|
registerDirective("soundListenerPosition", SoundListenerPosition);
|
|
1062
1072
|
|
|
1063
1073
|
// src/directives/Drag.ts
|
|
1064
|
-
import { effect as effect2, isSignal } from "@signe/reactive";
|
|
1065
|
-
import { Rectangle } from "pixi.js";
|
|
1074
|
+
import { effect as effect2, isSignal as isSignal3 } from "@signe/reactive";
|
|
1075
|
+
import { Rectangle, Point } from "pixi.js";
|
|
1066
1076
|
import { snap } from "popmotion";
|
|
1067
1077
|
|
|
1068
|
-
// src/
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
onMount(element) {
|
|
1075
|
-
const { image } = element.props.transition;
|
|
1076
|
-
const displacementSprite = new Sprite(Texture.from(image));
|
|
1077
|
-
displacementSprite.texture.baseTexture.wrapMode = WRAP_MODES.REPEAT;
|
|
1078
|
-
const displacementFilter = new DisplacementFilter(displacementSprite);
|
|
1079
|
-
const instance = element.componentInstance;
|
|
1080
|
-
instance.filters = [displacementFilter];
|
|
1081
|
-
instance.addChild(displacementSprite);
|
|
1082
|
-
setTimeout(() => {
|
|
1083
|
-
animate({
|
|
1084
|
-
from: 0,
|
|
1085
|
-
to: 1,
|
|
1086
|
-
duration: 500,
|
|
1087
|
-
onUpdate: (progress) => {
|
|
1088
|
-
displacementFilter.scale.x = progress;
|
|
1089
|
-
displacementFilter.scale.y = progress;
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
}, 5e3);
|
|
1093
|
-
}
|
|
1094
|
-
onUpdate(props) {
|
|
1095
|
-
}
|
|
1096
|
-
onDestroy() {
|
|
1097
|
-
}
|
|
1078
|
+
// src/hooks/addContext.ts
|
|
1079
|
+
var addContext = (element, key, value) => {
|
|
1080
|
+
element.props.context = {
|
|
1081
|
+
...element.props.context ?? {},
|
|
1082
|
+
[key]: value
|
|
1083
|
+
};
|
|
1098
1084
|
};
|
|
1099
|
-
registerDirective("transition", Transition);
|
|
1100
|
-
|
|
1101
|
-
// src/index.ts
|
|
1102
|
-
export * from "@signe/reactive";
|
|
1103
|
-
import { Howler } from "howler";
|
|
1104
1085
|
|
|
1105
|
-
// src/
|
|
1106
|
-
import {
|
|
1107
|
-
import { Container as Container3, autoDetectRenderer } from "pixi.js";
|
|
1108
|
-
import { loadYoga } from "yoga-layout";
|
|
1086
|
+
// src/hooks/useProps.ts
|
|
1087
|
+
import { isSignal as isSignal2, signal } from "@signe/reactive";
|
|
1109
1088
|
|
|
1110
1089
|
// src/engine/reactive.ts
|
|
1111
|
-
import { isSignal
|
|
1090
|
+
import { isSignal } from "@signe/reactive";
|
|
1112
1091
|
import {
|
|
1113
1092
|
Observable,
|
|
1114
1093
|
Subject,
|
|
@@ -1138,7 +1117,7 @@ function destroyElement(element) {
|
|
|
1138
1117
|
element.propSubscriptions.forEach((sub) => sub.unsubscribe());
|
|
1139
1118
|
element.effectSubscriptions.forEach((sub) => sub.unsubscribe());
|
|
1140
1119
|
for (let name in element.directives) {
|
|
1141
|
-
element.directives[name].onDestroy?.();
|
|
1120
|
+
element.directives[name].onDestroy?.(element);
|
|
1142
1121
|
}
|
|
1143
1122
|
element.componentInstance.onDestroy?.(element.parent);
|
|
1144
1123
|
element.effectUnmounts.forEach((fn) => fn?.());
|
|
@@ -1174,7 +1153,7 @@ function createComponent(tag, props) {
|
|
|
1174
1153
|
set(element.props, path2 + "." + key, value);
|
|
1175
1154
|
};
|
|
1176
1155
|
Object.entries(props2).forEach(([key, value]) => {
|
|
1177
|
-
if (
|
|
1156
|
+
if (isSignal(value)) {
|
|
1178
1157
|
const _value = value;
|
|
1179
1158
|
if ("dependencies" in _value && _value.dependencies.size == 0) {
|
|
1180
1159
|
_set(path, key, _value());
|
|
@@ -1184,7 +1163,7 @@ function createComponent(tag, props) {
|
|
|
1184
1163
|
_value.observable.subscribe((value2) => {
|
|
1185
1164
|
_set(path, key, value2);
|
|
1186
1165
|
if (element.directives[key]) {
|
|
1187
|
-
element.directives[key].onUpdate?.(value2);
|
|
1166
|
+
element.directives[key].onUpdate?.(value2, element);
|
|
1188
1167
|
}
|
|
1189
1168
|
if (key == "tick") {
|
|
1190
1169
|
return;
|
|
@@ -1235,7 +1214,7 @@ function createComponent(tag, props) {
|
|
|
1235
1214
|
;
|
|
1236
1215
|
async function propagateContext(element2) {
|
|
1237
1216
|
if (element2.props.attach) {
|
|
1238
|
-
const isReactiveAttach =
|
|
1217
|
+
const isReactiveAttach = isSignal(element2.propObservables?.attach);
|
|
1239
1218
|
if (!isReactiveAttach) {
|
|
1240
1219
|
element2.props.children.push(element2.props.attach);
|
|
1241
1220
|
} else {
|
|
@@ -1310,7 +1289,7 @@ function loop(itemsSubject, createElementFn) {
|
|
|
1310
1289
|
let elements = [];
|
|
1311
1290
|
let elementMap = /* @__PURE__ */ new Map();
|
|
1312
1291
|
let isFirstSubscription = true;
|
|
1313
|
-
const isArraySignal = (
|
|
1292
|
+
const isArraySignal = (signal8) => Array.isArray(signal8());
|
|
1314
1293
|
return new Observable((subscriber) => {
|
|
1315
1294
|
const subscription = isArraySignal(itemsSubject) ? itemsSubject.observable.subscribe((change) => {
|
|
1316
1295
|
if (isFirstSubscription) {
|
|
@@ -1439,7 +1418,7 @@ function loop(itemsSubject, createElementFn) {
|
|
|
1439
1418
|
}
|
|
1440
1419
|
function cond(condition, createElementFn) {
|
|
1441
1420
|
let element = null;
|
|
1442
|
-
if (
|
|
1421
|
+
if (isSignal(condition)) {
|
|
1443
1422
|
const signalCondition = condition;
|
|
1444
1423
|
return new Observable((subscriber) => {
|
|
1445
1424
|
return signalCondition.observable.subscribe((bool) => {
|
|
@@ -1495,9 +1474,8 @@ function cond(condition, createElementFn) {
|
|
|
1495
1474
|
}
|
|
1496
1475
|
|
|
1497
1476
|
// src/hooks/useProps.ts
|
|
1498
|
-
import { isSignal as isSignal3, signal } from "@signe/reactive";
|
|
1499
1477
|
var useProps = (props, defaults = {}) => {
|
|
1500
|
-
if (
|
|
1478
|
+
if (isSignal2(props)) {
|
|
1501
1479
|
return props();
|
|
1502
1480
|
}
|
|
1503
1481
|
const obj = {};
|
|
@@ -1507,14 +1485,14 @@ var useProps = (props, defaults = {}) => {
|
|
|
1507
1485
|
}
|
|
1508
1486
|
for (let key in defaults) {
|
|
1509
1487
|
if (!(key in obj)) {
|
|
1510
|
-
obj[key] = signal(defaults[key]);
|
|
1488
|
+
obj[key] = isPrimitive(defaults[key]) ? signal(defaults[key]) : defaults[key];
|
|
1511
1489
|
}
|
|
1512
1490
|
}
|
|
1513
1491
|
return obj;
|
|
1514
1492
|
};
|
|
1515
1493
|
var useDefineProps = (props) => {
|
|
1516
1494
|
return (schema) => {
|
|
1517
|
-
const rawProps =
|
|
1495
|
+
const rawProps = isSignal2(props) ? props() : props;
|
|
1518
1496
|
const validatedProps = {};
|
|
1519
1497
|
for (const key in schema) {
|
|
1520
1498
|
const propConfig = schema[key];
|
|
@@ -1543,7 +1521,7 @@ var useDefineProps = (props) => {
|
|
|
1543
1521
|
validatedValue = value;
|
|
1544
1522
|
}
|
|
1545
1523
|
}
|
|
1546
|
-
validatedProps[key] =
|
|
1524
|
+
validatedProps[key] = isSignal2(validatedValue) ? validatedValue : signal(validatedValue);
|
|
1547
1525
|
}
|
|
1548
1526
|
return {
|
|
1549
1527
|
...useProps(rawProps),
|
|
@@ -1553,7 +1531,7 @@ var useDefineProps = (props) => {
|
|
|
1553
1531
|
};
|
|
1554
1532
|
function validateType(key, value, types) {
|
|
1555
1533
|
if (value === void 0 || value === null) return;
|
|
1556
|
-
const valueToCheck =
|
|
1534
|
+
const valueToCheck = isSignal2(value) ? value() : value;
|
|
1557
1535
|
const valid = types.some((type) => {
|
|
1558
1536
|
if (type === Number) return typeof valueToCheck === "number";
|
|
1559
1537
|
if (type === String) return typeof valueToCheck === "string";
|
|
@@ -1571,8 +1549,277 @@ function validateType(key, value, types) {
|
|
|
1571
1549
|
}
|
|
1572
1550
|
}
|
|
1573
1551
|
|
|
1552
|
+
// src/directives/Drag.ts
|
|
1553
|
+
var Drop = class extends Directive {
|
|
1554
|
+
constructor() {
|
|
1555
|
+
super(...arguments);
|
|
1556
|
+
this.elementRef = null;
|
|
1557
|
+
}
|
|
1558
|
+
onInit(element) {
|
|
1559
|
+
this.elementRef = element;
|
|
1560
|
+
}
|
|
1561
|
+
onMount(element) {
|
|
1562
|
+
addContext(element, "drop", element);
|
|
1563
|
+
}
|
|
1564
|
+
onUpdate() {
|
|
1565
|
+
}
|
|
1566
|
+
onDestroy() {
|
|
1567
|
+
this.elementRef = null;
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
var Drag = class extends Directive {
|
|
1571
|
+
constructor() {
|
|
1572
|
+
super(...arguments);
|
|
1573
|
+
this.elementRef = null;
|
|
1574
|
+
this.stageRef = null;
|
|
1575
|
+
this.offsetInParent = new Point();
|
|
1576
|
+
this.isDragging = false;
|
|
1577
|
+
this.viewport = null;
|
|
1578
|
+
this.animationFrameId = null;
|
|
1579
|
+
this.lastPointerPosition = new Point();
|
|
1580
|
+
this.onDragMoveHandler = () => {
|
|
1581
|
+
};
|
|
1582
|
+
this.onDragEndHandler = () => {
|
|
1583
|
+
};
|
|
1584
|
+
this.onDragStartHandler = () => {
|
|
1585
|
+
};
|
|
1586
|
+
this.subscriptions = [];
|
|
1587
|
+
}
|
|
1588
|
+
onInit(element) {
|
|
1589
|
+
this.elementRef = element;
|
|
1590
|
+
this.onDragMoveHandler = this.onDragMove.bind(this);
|
|
1591
|
+
this.onDragEndHandler = this.onDragEnd.bind(this);
|
|
1592
|
+
this.onDragStartHandler = this.onPointerDown.bind(this);
|
|
1593
|
+
}
|
|
1594
|
+
onMount(element) {
|
|
1595
|
+
const { rootElement, canvasSize, viewport, tick: tick2 } = element.props.context;
|
|
1596
|
+
const instance = element.componentInstance;
|
|
1597
|
+
const dragProps = this.dragProps;
|
|
1598
|
+
const haveNotProps = Object.keys(dragProps).length === 0;
|
|
1599
|
+
if (haveNotProps) {
|
|
1600
|
+
this.onDestroy();
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
if (!instance) return;
|
|
1604
|
+
this.stageRef = rootElement.componentInstance;
|
|
1605
|
+
if (!this.stageRef) return;
|
|
1606
|
+
this.viewport = viewport;
|
|
1607
|
+
instance.eventMode = "static";
|
|
1608
|
+
this.stageRef.eventMode = "static";
|
|
1609
|
+
const _effect = effect2(() => {
|
|
1610
|
+
if (this.stageRef) {
|
|
1611
|
+
this.stageRef.hitArea = new Rectangle(0, 0, canvasSize().width, canvasSize().height);
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
instance.on("pointerdown", this.onDragStartHandler);
|
|
1615
|
+
this.stageRef.on("pointerup", this.onDragEndHandler);
|
|
1616
|
+
this.stageRef.on("pointerupoutside", this.onDragEndHandler);
|
|
1617
|
+
this.subscriptions = [
|
|
1618
|
+
tick2.observable.subscribe(() => {
|
|
1619
|
+
if (this.isDragging && this.viewport) {
|
|
1620
|
+
this.updateViewportPosition(this.lastPointerPosition);
|
|
1621
|
+
}
|
|
1622
|
+
}),
|
|
1623
|
+
_effect.subscription
|
|
1624
|
+
];
|
|
1625
|
+
}
|
|
1626
|
+
get dragProps() {
|
|
1627
|
+
const drag = this.elementRef?.props.drag;
|
|
1628
|
+
const options = useProps(drag?.value ?? drag, {
|
|
1629
|
+
snap: 0,
|
|
1630
|
+
viewport: {},
|
|
1631
|
+
direction: "all"
|
|
1632
|
+
});
|
|
1633
|
+
options.viewport = useProps(options.viewport, {
|
|
1634
|
+
edgeThreshold: 300,
|
|
1635
|
+
maxSpeed: 40
|
|
1636
|
+
});
|
|
1637
|
+
return options;
|
|
1638
|
+
}
|
|
1639
|
+
get axis() {
|
|
1640
|
+
const direction = this.dragProps.direction();
|
|
1641
|
+
const axis = {
|
|
1642
|
+
x: true,
|
|
1643
|
+
y: true
|
|
1644
|
+
};
|
|
1645
|
+
if (direction === "x") {
|
|
1646
|
+
axis.y = false;
|
|
1647
|
+
}
|
|
1648
|
+
if (direction === "y") {
|
|
1649
|
+
axis.x = false;
|
|
1650
|
+
}
|
|
1651
|
+
return axis;
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Updates element position when dragging and starts continuous viewport movement
|
|
1655
|
+
* @param event The pointer event that triggered the drag move
|
|
1656
|
+
*/
|
|
1657
|
+
onDragMove(event) {
|
|
1658
|
+
if (!this.isDragging || !this.elementRef?.componentInstance || !this.elementRef.componentInstance.parent) return;
|
|
1659
|
+
const instance = this.elementRef.componentInstance;
|
|
1660
|
+
const parent = instance.parent;
|
|
1661
|
+
const dragProps = this.dragProps;
|
|
1662
|
+
const propObservables = this.elementRef.propObservables;
|
|
1663
|
+
const snapTo = snap(dragProps?.snap() ?? 0);
|
|
1664
|
+
dragProps?.move?.(event);
|
|
1665
|
+
const currentParentLocalPointer = parent.toLocal(event.global);
|
|
1666
|
+
const newX = currentParentLocalPointer.x - this.offsetInParent.x;
|
|
1667
|
+
const newY = currentParentLocalPointer.y - this.offsetInParent.y;
|
|
1668
|
+
if (dragProps?.snap()) {
|
|
1669
|
+
instance.position.x = snapTo(newX);
|
|
1670
|
+
instance.position.y = snapTo(newY);
|
|
1671
|
+
} else {
|
|
1672
|
+
if (this.axis.x) instance.position.x = newX;
|
|
1673
|
+
if (this.axis.y) instance.position.y = newY;
|
|
1674
|
+
}
|
|
1675
|
+
this.lastPointerPosition.copyFrom(event.global);
|
|
1676
|
+
const { x: xProp, y: yProp } = propObservables;
|
|
1677
|
+
if (xProp !== void 0 && isSignal3(xProp)) {
|
|
1678
|
+
}
|
|
1679
|
+
if (yProp !== void 0 && isSignal3(yProp)) {
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Moves the viewport if the dragged element is near screen edges
|
|
1684
|
+
* @param globalPosition The global pointer position
|
|
1685
|
+
*/
|
|
1686
|
+
updateViewportPosition(globalPosition) {
|
|
1687
|
+
if (!this.viewport || !this.elementRef) return;
|
|
1688
|
+
const dragProps = this.dragProps;
|
|
1689
|
+
const edgeThreshold = dragProps?.viewport?.edgeThreshold();
|
|
1690
|
+
const maxSpeed = dragProps?.viewport?.maxSpeed();
|
|
1691
|
+
const screenLeft = 0;
|
|
1692
|
+
const screenRight = this.viewport.screenWidth;
|
|
1693
|
+
const screenTop = 0;
|
|
1694
|
+
const screenBottom = this.viewport.screenHeight;
|
|
1695
|
+
const instance = this.elementRef.componentInstance;
|
|
1696
|
+
const distanceFromLeft = globalPosition.x - screenLeft;
|
|
1697
|
+
const distanceFromRight = screenRight - globalPosition.x;
|
|
1698
|
+
const distanceFromTop = globalPosition.y - screenTop;
|
|
1699
|
+
const distanceFromBottom = screenBottom - globalPosition.y;
|
|
1700
|
+
let moveX = 0;
|
|
1701
|
+
let moveY = 0;
|
|
1702
|
+
if (distanceFromLeft < edgeThreshold) {
|
|
1703
|
+
const velocity = maxSpeed * (1 - distanceFromLeft / edgeThreshold);
|
|
1704
|
+
moveX = -velocity;
|
|
1705
|
+
} else if (distanceFromRight < edgeThreshold) {
|
|
1706
|
+
const velocity = maxSpeed * (1 - distanceFromRight / edgeThreshold);
|
|
1707
|
+
moveX = velocity;
|
|
1708
|
+
}
|
|
1709
|
+
if (distanceFromTop < edgeThreshold) {
|
|
1710
|
+
const velocity = maxSpeed * (1 - distanceFromTop / edgeThreshold);
|
|
1711
|
+
moveY = -velocity;
|
|
1712
|
+
} else if (distanceFromBottom < edgeThreshold) {
|
|
1713
|
+
const velocity = maxSpeed * (1 - distanceFromBottom / edgeThreshold);
|
|
1714
|
+
moveY = velocity;
|
|
1715
|
+
}
|
|
1716
|
+
if (moveX !== 0 || moveY !== 0) {
|
|
1717
|
+
const lastViewValue = this.viewport.center;
|
|
1718
|
+
this.viewport.moveCenter(
|
|
1719
|
+
this.viewport.center.x + moveX,
|
|
1720
|
+
this.viewport.center.y + moveY
|
|
1721
|
+
);
|
|
1722
|
+
if (this.axis.x && lastViewValue.x !== this.viewport.center.x) {
|
|
1723
|
+
instance.position.x += moveX;
|
|
1724
|
+
}
|
|
1725
|
+
if (this.axis.y && lastViewValue.y !== this.viewport.center.y) {
|
|
1726
|
+
instance.position.y += moveY;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Handles drag end event and stops viewport movement
|
|
1732
|
+
*/
|
|
1733
|
+
onDragEnd() {
|
|
1734
|
+
if (!this.isDragging || !this.elementRef) return;
|
|
1735
|
+
const dragProps = this.dragProps;
|
|
1736
|
+
this.isDragging = false;
|
|
1737
|
+
dragProps?.end?.();
|
|
1738
|
+
if (this.stageRef) {
|
|
1739
|
+
this.stageRef.off("pointermove", this.onDragMoveHandler);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
onPointerDown(event) {
|
|
1743
|
+
if (!this.elementRef?.componentInstance || !this.stageRef || !this.elementRef.componentInstance.parent) return;
|
|
1744
|
+
const instance = this.elementRef.componentInstance;
|
|
1745
|
+
const parent = instance.parent;
|
|
1746
|
+
const dragProps = this.dragProps;
|
|
1747
|
+
const parentLocalPointer = parent.toLocal(event.global);
|
|
1748
|
+
this.offsetInParent.x = parentLocalPointer.x - instance.position.x;
|
|
1749
|
+
this.offsetInParent.y = parentLocalPointer.y - instance.position.y;
|
|
1750
|
+
this.isDragging = true;
|
|
1751
|
+
this.lastPointerPosition.copyFrom(event.global);
|
|
1752
|
+
dragProps?.start?.();
|
|
1753
|
+
this.stageRef.on("pointermove", this.onDragMoveHandler);
|
|
1754
|
+
}
|
|
1755
|
+
onUpdate(props) {
|
|
1756
|
+
if (props.type && props.type === "reset") {
|
|
1757
|
+
this.onDestroy();
|
|
1758
|
+
this.onMount(this.elementRef);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
onDestroy() {
|
|
1762
|
+
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
1763
|
+
const instance = this.elementRef?.componentInstance;
|
|
1764
|
+
if (instance) {
|
|
1765
|
+
instance.off("pointerdown", this.onDragStartHandler);
|
|
1766
|
+
}
|
|
1767
|
+
if (this.stageRef) {
|
|
1768
|
+
this.stageRef.off("pointermove", this.onDragMoveHandler);
|
|
1769
|
+
this.stageRef.off("pointerup", this.onDragEndHandler);
|
|
1770
|
+
this.stageRef.off("pointerupoutside", this.onDragEndHandler);
|
|
1771
|
+
}
|
|
1772
|
+
this.stageRef = null;
|
|
1773
|
+
this.viewport = null;
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
registerDirective("drag", Drag);
|
|
1777
|
+
registerDirective("drop", Drop);
|
|
1778
|
+
|
|
1779
|
+
// src/directives/Transition.ts
|
|
1780
|
+
import { DisplacementFilter, Sprite, Texture, WRAP_MODES } from "pixi.js";
|
|
1781
|
+
import { animate } from "popmotion";
|
|
1782
|
+
var Transition = class extends Directive {
|
|
1783
|
+
onInit(element) {
|
|
1784
|
+
}
|
|
1785
|
+
onMount(element) {
|
|
1786
|
+
const { image } = element.props.transition;
|
|
1787
|
+
const displacementSprite = new Sprite(Texture.from(image));
|
|
1788
|
+
displacementSprite.texture.baseTexture.wrapMode = WRAP_MODES.REPEAT;
|
|
1789
|
+
const displacementFilter = new DisplacementFilter(displacementSprite);
|
|
1790
|
+
const instance = element.componentInstance;
|
|
1791
|
+
instance.filters = [displacementFilter];
|
|
1792
|
+
instance.addChild(displacementSprite);
|
|
1793
|
+
setTimeout(() => {
|
|
1794
|
+
animate({
|
|
1795
|
+
from: 0,
|
|
1796
|
+
to: 1,
|
|
1797
|
+
duration: 500,
|
|
1798
|
+
onUpdate: (progress) => {
|
|
1799
|
+
displacementFilter.scale.x = progress;
|
|
1800
|
+
displacementFilter.scale.y = progress;
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
}, 5e3);
|
|
1804
|
+
}
|
|
1805
|
+
onUpdate(props) {
|
|
1806
|
+
}
|
|
1807
|
+
onDestroy() {
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
registerDirective("transition", Transition);
|
|
1811
|
+
|
|
1812
|
+
// src/index.ts
|
|
1813
|
+
export * from "@signe/reactive";
|
|
1814
|
+
import { Howler } from "howler";
|
|
1815
|
+
|
|
1816
|
+
// src/components/Canvas.ts
|
|
1817
|
+
import { effect as effect4, signal as signal4 } from "@signe/reactive";
|
|
1818
|
+
import { Container as Container3, autoDetectRenderer } from "pixi.js";
|
|
1819
|
+
import { loadYoga } from "yoga-layout";
|
|
1820
|
+
|
|
1574
1821
|
// src/components/DisplayObject.ts
|
|
1575
|
-
import { effect as effect3, signal as
|
|
1822
|
+
import { effect as effect3, signal as signal3 } from "@signe/reactive";
|
|
1576
1823
|
import { DropShadowFilter } from "pixi-filters";
|
|
1577
1824
|
import { BlurFilter, ObservablePoint } from "pixi.js";
|
|
1578
1825
|
var EVENTS2 = [
|
|
@@ -1662,8 +1909,8 @@ function DisplayObject(extendClass) {
|
|
|
1662
1909
|
0
|
|
1663
1910
|
);
|
|
1664
1911
|
this.isCustomAnchor = false;
|
|
1665
|
-
this.displayWidth =
|
|
1666
|
-
this.displayHeight =
|
|
1912
|
+
this.displayWidth = signal3(0);
|
|
1913
|
+
this.displayHeight = signal3(0);
|
|
1667
1914
|
this.overrideProps = [];
|
|
1668
1915
|
}
|
|
1669
1916
|
get yoga() {
|
|
@@ -1959,14 +2206,14 @@ registerComponent("Canvas", class Canvas extends DisplayObject(Container3) {
|
|
|
1959
2206
|
var Canvas2 = async (props = {}) => {
|
|
1960
2207
|
let { cursorStyles, width, height, class: className } = useProps(props);
|
|
1961
2208
|
const Yoga = await loadYoga();
|
|
1962
|
-
if (!props.width) width =
|
|
1963
|
-
if (!props.height) height =
|
|
2209
|
+
if (!props.width) width = signal4(800);
|
|
2210
|
+
if (!props.height) height = signal4(600);
|
|
1964
2211
|
const renderer = await autoDetectRenderer({
|
|
1965
2212
|
...props,
|
|
1966
2213
|
width: width?.(),
|
|
1967
2214
|
height: height?.()
|
|
1968
2215
|
});
|
|
1969
|
-
const canvasSize =
|
|
2216
|
+
const canvasSize = signal4({
|
|
1970
2217
|
width: renderer.width,
|
|
1971
2218
|
height: renderer.height
|
|
1972
2219
|
});
|
|
@@ -1982,7 +2229,7 @@ var Canvas2 = async (props = {}) => {
|
|
|
1982
2229
|
height: height?.()
|
|
1983
2230
|
};
|
|
1984
2231
|
if (!props.tick) {
|
|
1985
|
-
options.context.tick = options.tick =
|
|
2232
|
+
options.context.tick = options.tick = signal4({
|
|
1986
2233
|
timestamp: 0,
|
|
1987
2234
|
deltaTime: 0,
|
|
1988
2235
|
frame: 0,
|
|
@@ -2268,10 +2515,10 @@ import {
|
|
|
2268
2515
|
} from "pixi.js";
|
|
2269
2516
|
|
|
2270
2517
|
// src/engine/animation.ts
|
|
2271
|
-
import { effect as effect6, signal as
|
|
2518
|
+
import { effect as effect6, signal as signal5 } from "@signe/reactive";
|
|
2272
2519
|
import { animate as animatePopmotion } from "popmotion";
|
|
2273
|
-
function isAnimatedSignal(
|
|
2274
|
-
return
|
|
2520
|
+
function isAnimatedSignal(signal8) {
|
|
2521
|
+
return signal8.animatedState !== void 0;
|
|
2275
2522
|
}
|
|
2276
2523
|
function animatedSignal(initialValue, options = {}) {
|
|
2277
2524
|
const state = {
|
|
@@ -2280,8 +2527,8 @@ function animatedSignal(initialValue, options = {}) {
|
|
|
2280
2527
|
end: initialValue
|
|
2281
2528
|
};
|
|
2282
2529
|
let animation;
|
|
2283
|
-
const publicSignal =
|
|
2284
|
-
const privateSignal =
|
|
2530
|
+
const publicSignal = signal5(initialValue);
|
|
2531
|
+
const privateSignal = signal5(state);
|
|
2285
2532
|
effect6(() => {
|
|
2286
2533
|
const currentState = privateSignal();
|
|
2287
2534
|
publicSignal.set(currentState.current);
|
|
@@ -2663,7 +2910,7 @@ var Sprite2 = (props) => {
|
|
|
2663
2910
|
};
|
|
2664
2911
|
|
|
2665
2912
|
// src/components/Video.ts
|
|
2666
|
-
import { effect as effect8, signal as
|
|
2913
|
+
import { effect as effect8, signal as signal6 } from "@signe/reactive";
|
|
2667
2914
|
function Video(props) {
|
|
2668
2915
|
const eventsMap = {
|
|
2669
2916
|
audioprocess: null,
|
|
@@ -2688,7 +2935,7 @@ function Video(props) {
|
|
|
2688
2935
|
volumechange: null,
|
|
2689
2936
|
waiting: null
|
|
2690
2937
|
};
|
|
2691
|
-
const video =
|
|
2938
|
+
const video = signal6(null);
|
|
2692
2939
|
const defineProps = useDefineProps(props);
|
|
2693
2940
|
const { play, loop: loop2, muted } = defineProps({
|
|
2694
2941
|
play: {
|
|
@@ -2758,12 +3005,12 @@ function Video(props) {
|
|
|
2758
3005
|
import { Text as PixiText } from "pixi.js";
|
|
2759
3006
|
|
|
2760
3007
|
// src/engine/trigger.ts
|
|
2761
|
-
import { effect as effect9, signal as
|
|
3008
|
+
import { effect as effect9, signal as signal7 } from "@signe/reactive";
|
|
2762
3009
|
function isTrigger(arg) {
|
|
2763
3010
|
return arg?.start && arg?.listen;
|
|
2764
3011
|
}
|
|
2765
3012
|
function trigger(globalConfig) {
|
|
2766
|
-
const _signal =
|
|
3013
|
+
const _signal = signal7({
|
|
2767
3014
|
config: globalConfig,
|
|
2768
3015
|
value: 0,
|
|
2769
3016
|
resolve: (value) => void 0
|
|
@@ -2981,10 +3228,7 @@ var CanvasViewport = class extends DisplayObject(PixiViewport) {
|
|
|
2981
3228
|
onInit(props) {
|
|
2982
3229
|
super.onInit(props);
|
|
2983
3230
|
for (let event of EVENTS3) {
|
|
2984
|
-
|
|
2985
|
-
if (props[camelCaseEvent]) {
|
|
2986
|
-
this.on(event, props[camelCaseEvent]);
|
|
2987
|
-
}
|
|
3231
|
+
if (props[event]) this.on(event, props[event]);
|
|
2988
3232
|
}
|
|
2989
3233
|
}
|
|
2990
3234
|
onMount(element) {
|
|
@@ -3023,8 +3267,11 @@ var CanvasViewport = class extends DisplayObject(PixiViewport) {
|
|
|
3023
3267
|
if (props.worldHeight !== void 0) {
|
|
3024
3268
|
this.worldHeight = props.worldHeight;
|
|
3025
3269
|
}
|
|
3270
|
+
if (props.drag) {
|
|
3271
|
+
this.drag(props.drag);
|
|
3272
|
+
}
|
|
3026
3273
|
if (props.clamp) {
|
|
3027
|
-
this.clamp(props.clamp);
|
|
3274
|
+
this.clamp(props.clamp.value ?? props.clamp);
|
|
3028
3275
|
}
|
|
3029
3276
|
if (props.wheel) {
|
|
3030
3277
|
if (props.wheel === true) {
|