locusing 0.1.0
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/LICENSE +21 -0
- package/README.md +147 -0
- package/dist/chunk-2THKOSBL.mjs +421 -0
- package/dist/index.d.mts +1411 -0
- package/dist/index.d.ts +1411 -0
- package/dist/index.js +4097 -0
- package/dist/index.mjs +3487 -0
- package/dist/transform-TMK5SL54.mjs +14 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yao Shen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Locusing
|
|
2
|
+
|
|
3
|
+
A declarative graphics and animation library for mathematical visualization.
|
|
4
|
+
|
|
5
|
+
Locusing combines the elegance of [Manim](https://www.manim.community/) with the interactivity of [Diagramatics](https://github.com/ray-x/diagramatics), bringing beautiful mathematical animations to the web.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Declarative API** - Immutable, composable diagram primitives
|
|
10
|
+
- **Manim-style Animations** - 30+ built-in animations (Create, FadeIn, Transform, etc.)
|
|
11
|
+
- **Interactive Controls** - Sliders, draggable points, and constraints
|
|
12
|
+
- **Hand-drawn Style** - Rough.js integration for sketch-like graphics
|
|
13
|
+
- **Mathematical Tools** - Vectors, matrices, Bezier curves, coordinate systems
|
|
14
|
+
- **Geometry Constructions** - Compass-and-straightedge style constructions
|
|
15
|
+
|
|
16
|
+
## Packages
|
|
17
|
+
|
|
18
|
+
| Package | Description |
|
|
19
|
+
|:--------|:------------|
|
|
20
|
+
| `@wangyaoshen/core` | Core rendering engine with SVG and Rough.js support |
|
|
21
|
+
| `@wangyaoshen/animate` | Manim-style animation system powered by GSAP |
|
|
22
|
+
| `@wangyaoshen/math` | Mathematical utilities (vectors, matrices, curves) |
|
|
23
|
+
| `@wangyaoshen/geometry` | Coordinate systems and geometric constructions |
|
|
24
|
+
| `@wangyaoshen/interactive` | Interactive controls and constraints |
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Install packages
|
|
30
|
+
pnpm add @wangyaoshen/core @wangyaoshen/animate @wangyaoshen/math
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Static Diagram
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { square, circle, text, combine, renderToSVG } from '@wangyaoshen/core';
|
|
37
|
+
|
|
38
|
+
// Create shapes
|
|
39
|
+
const sq = square(100).fill('#EA580C');
|
|
40
|
+
const label = text('Hello').translate(0, 80);
|
|
41
|
+
|
|
42
|
+
// Combine and render
|
|
43
|
+
const diagram = combine(sq, label);
|
|
44
|
+
renderToSVG(diagram, document.getElementById('canvas'));
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Animated Scene
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Scene, Create, FadeOut, Wait } from '@wangyaoshen/animate';
|
|
51
|
+
import { square, circle } from '@wangyaoshen/core';
|
|
52
|
+
|
|
53
|
+
class MyScene extends Scene {
|
|
54
|
+
construct() {
|
|
55
|
+
const sq = square(100).fill('#EA580C');
|
|
56
|
+
const c = circle(50).fill('#58C4DD');
|
|
57
|
+
|
|
58
|
+
this.play(Create(sq));
|
|
59
|
+
this.play(Create(c, { delay: 0.5 }));
|
|
60
|
+
this.wait(1);
|
|
61
|
+
this.play(FadeOut(sq), FadeOut(c));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const scene = new MyScene(document.getElementById('canvas'));
|
|
66
|
+
scene.render();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Interactive Diagram
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Interactive } from '@wangyaoshen/interactive';
|
|
73
|
+
import { circle } from '@wangyaoshen/core';
|
|
74
|
+
|
|
75
|
+
const interactive = new Interactive(container);
|
|
76
|
+
|
|
77
|
+
interactive.slider({
|
|
78
|
+
min: 10,
|
|
79
|
+
max: 100,
|
|
80
|
+
value: 50,
|
|
81
|
+
onChange: (radius) => {
|
|
82
|
+
const c = circle(radius).fill('#EA580C');
|
|
83
|
+
interactive.update(c);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Animation Library
|
|
89
|
+
|
|
90
|
+
### Creation Animations
|
|
91
|
+
- `Create` - Draw stroke animation
|
|
92
|
+
- `Write` - Text writing effect
|
|
93
|
+
- `GrowFromCenter` - Scale from center
|
|
94
|
+
- `DrawBorderThenFill` - Draw border then fill
|
|
95
|
+
|
|
96
|
+
### Fade Animations
|
|
97
|
+
- `FadeIn` / `FadeOut`
|
|
98
|
+
- `FadeInFrom` / `FadeOutTo`
|
|
99
|
+
|
|
100
|
+
### Transform Animations
|
|
101
|
+
- `Transform` - Morph between shapes
|
|
102
|
+
- `ReplacementTransform` - Replace with transform
|
|
103
|
+
- `Morphing` - SVG path morphing (requires GSAP MorphSVG)
|
|
104
|
+
|
|
105
|
+
### Movement Animations
|
|
106
|
+
- `Shift` - Relative movement
|
|
107
|
+
- `MoveTo` - Absolute movement
|
|
108
|
+
- `MoveAlongPath` - Follow a path
|
|
109
|
+
- `Rotate` / `Scale`
|
|
110
|
+
|
|
111
|
+
### Indication Animations
|
|
112
|
+
- `Indicate` - Highlight effect
|
|
113
|
+
- `Circumscribe` - Circle around
|
|
114
|
+
- `Wiggle` - Shake effect
|
|
115
|
+
- `Flash` - Flash effect
|
|
116
|
+
|
|
117
|
+
### Composition
|
|
118
|
+
- `Succession` - Play in sequence
|
|
119
|
+
- `LaggedStart` - Staggered start times
|
|
120
|
+
|
|
121
|
+
## Development
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Install dependencies
|
|
125
|
+
pnpm install
|
|
126
|
+
|
|
127
|
+
# Run playground
|
|
128
|
+
pnpm dev
|
|
129
|
+
|
|
130
|
+
# Build all packages
|
|
131
|
+
pnpm build
|
|
132
|
+
|
|
133
|
+
# Run tests
|
|
134
|
+
pnpm test
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Credits
|
|
138
|
+
|
|
139
|
+
- [GSAP](https://gsap.com/) - Animation engine
|
|
140
|
+
- [Rough.js](https://roughjs.com/) - Hand-drawn style graphics
|
|
141
|
+
- [KaTeX](https://katex.org/) - LaTeX rendering (playground)
|
|
142
|
+
- [Manim](https://www.manim.community/) - Animation API inspiration
|
|
143
|
+
- [Diagramatics](https://github.com/ray-x/diagramatics) - Interactive diagram inspiration
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/animate/animations/transform.ts
|
|
34
|
+
import { gsap as gsap2 } from "gsap";
|
|
35
|
+
|
|
36
|
+
// src/animate/timeline.ts
|
|
37
|
+
import { gsap } from "gsap";
|
|
38
|
+
var Timeline = class {
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this._status = "pending";
|
|
41
|
+
this.timeline = gsap.timeline({
|
|
42
|
+
paused: true,
|
|
43
|
+
onStart: () => {
|
|
44
|
+
var _a;
|
|
45
|
+
this._status = "running";
|
|
46
|
+
(_a = options.onStart) == null ? void 0 : _a.call(options);
|
|
47
|
+
},
|
|
48
|
+
onComplete: () => {
|
|
49
|
+
var _a;
|
|
50
|
+
this._status = "completed";
|
|
51
|
+
(_a = options.onComplete) == null ? void 0 : _a.call(options);
|
|
52
|
+
},
|
|
53
|
+
onUpdate: () => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = options.onUpdate) == null ? void 0 : _a.call(options, this.progress);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** 当前状态 */
|
|
60
|
+
get status() {
|
|
61
|
+
return this._status;
|
|
62
|
+
}
|
|
63
|
+
/** 当前进度 (0-1) */
|
|
64
|
+
get progress() {
|
|
65
|
+
return this.timeline.progress();
|
|
66
|
+
}
|
|
67
|
+
/** 总时长 */
|
|
68
|
+
get duration() {
|
|
69
|
+
return this.timeline.duration();
|
|
70
|
+
}
|
|
71
|
+
/** 当前时间 */
|
|
72
|
+
get time() {
|
|
73
|
+
return this.timeline.time();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 添加动画到时间线
|
|
77
|
+
*/
|
|
78
|
+
add(target, vars, position) {
|
|
79
|
+
this.timeline.to(target, vars, position);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 添加回调函数
|
|
84
|
+
*/
|
|
85
|
+
call(callback, position) {
|
|
86
|
+
this.timeline.call(callback, void 0, position);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 添加延迟
|
|
91
|
+
*/
|
|
92
|
+
delay(seconds, position) {
|
|
93
|
+
this.timeline.to({}, { duration: seconds }, position);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 添加标签
|
|
98
|
+
*/
|
|
99
|
+
label(name, position) {
|
|
100
|
+
this.timeline.addLabel(name, position);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 播放
|
|
105
|
+
*/
|
|
106
|
+
play() {
|
|
107
|
+
this._status = "running";
|
|
108
|
+
this.timeline.play();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 暂停
|
|
113
|
+
*/
|
|
114
|
+
pause() {
|
|
115
|
+
this._status = "paused";
|
|
116
|
+
this.timeline.pause();
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 恢复
|
|
121
|
+
*/
|
|
122
|
+
resume() {
|
|
123
|
+
this._status = "running";
|
|
124
|
+
this.timeline.resume();
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 停止并重置
|
|
129
|
+
*/
|
|
130
|
+
restart() {
|
|
131
|
+
this._status = "pending";
|
|
132
|
+
this.timeline.restart();
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 跳转到指定时间
|
|
137
|
+
*/
|
|
138
|
+
seek(time) {
|
|
139
|
+
this.timeline.seek(time);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 设置进度
|
|
144
|
+
*/
|
|
145
|
+
setProgress(progress) {
|
|
146
|
+
this.timeline.progress(progress);
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 设置速度
|
|
151
|
+
*/
|
|
152
|
+
setSpeed(speed) {
|
|
153
|
+
this.timeline.timeScale(speed);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 反向播放
|
|
158
|
+
*/
|
|
159
|
+
reverse() {
|
|
160
|
+
this.timeline.reverse();
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 销毁
|
|
165
|
+
*/
|
|
166
|
+
kill() {
|
|
167
|
+
this.timeline.kill();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 等待完成
|
|
171
|
+
*/
|
|
172
|
+
async finished() {
|
|
173
|
+
return new Promise((resolve) => {
|
|
174
|
+
this.timeline.eventCallback("onComplete", resolve);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
function createTimeline(options) {
|
|
179
|
+
return new Timeline(options);
|
|
180
|
+
}
|
|
181
|
+
var easingMap = {
|
|
182
|
+
linear: "none",
|
|
183
|
+
easeIn: "power2.in",
|
|
184
|
+
easeOut: "power2.out",
|
|
185
|
+
easeInOut: "power2.inOut",
|
|
186
|
+
easeInQuad: "power1.in",
|
|
187
|
+
easeOutQuad: "power1.out",
|
|
188
|
+
easeInOutQuad: "power1.inOut",
|
|
189
|
+
easeInCubic: "power2.in",
|
|
190
|
+
easeOutCubic: "power2.out",
|
|
191
|
+
easeInOutCubic: "power2.inOut",
|
|
192
|
+
easeInQuart: "power3.in",
|
|
193
|
+
easeOutQuart: "power3.out",
|
|
194
|
+
easeInOutQuart: "power3.inOut",
|
|
195
|
+
easeInQuint: "power4.in",
|
|
196
|
+
easeOutQuint: "power4.out",
|
|
197
|
+
easeInOutQuint: "power4.inOut",
|
|
198
|
+
easeInSine: "sine.in",
|
|
199
|
+
easeOutSine: "sine.out",
|
|
200
|
+
easeInOutSine: "sine.inOut",
|
|
201
|
+
easeInExpo: "expo.in",
|
|
202
|
+
easeOutExpo: "expo.out",
|
|
203
|
+
easeInOutExpo: "expo.inOut",
|
|
204
|
+
easeInCirc: "circ.in",
|
|
205
|
+
easeOutCirc: "circ.out",
|
|
206
|
+
easeInOutCirc: "circ.inOut",
|
|
207
|
+
easeInBack: "back.in",
|
|
208
|
+
easeOutBack: "back.out",
|
|
209
|
+
easeInOutBack: "back.inOut",
|
|
210
|
+
easeInElastic: "elastic.in",
|
|
211
|
+
easeOutElastic: "elastic.out",
|
|
212
|
+
easeInOutElastic: "elastic.inOut",
|
|
213
|
+
easeInBounce: "bounce.in",
|
|
214
|
+
easeOutBounce: "bounce.out",
|
|
215
|
+
easeInOutBounce: "bounce.inOut"
|
|
216
|
+
};
|
|
217
|
+
function getGSAPEasing(easing) {
|
|
218
|
+
return easingMap[easing] || easing;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/animate/animations/transform.ts
|
|
222
|
+
function Transform(source, target, options = {}) {
|
|
223
|
+
const { duration = 1, easing = "easeInOut", delay = 0 } = options;
|
|
224
|
+
return {
|
|
225
|
+
duration,
|
|
226
|
+
target: source,
|
|
227
|
+
execute(scene, timeline, startTime) {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
const sourceElement = scene.getElement(source);
|
|
230
|
+
const targetElement = scene.getOrCreateElement(target);
|
|
231
|
+
if (!sourceElement || !targetElement) return;
|
|
232
|
+
gsap2.set(targetElement, { opacity: 0 });
|
|
233
|
+
const sourceBBox = ((_a = sourceElement.getBBox) == null ? void 0 : _a.call(sourceElement)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
234
|
+
const targetBBox = ((_b = targetElement.getBBox) == null ? void 0 : _b.call(targetElement)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
235
|
+
const scaleX = targetBBox.width / (sourceBBox.width || 1);
|
|
236
|
+
const scaleY = targetBBox.height / (sourceBBox.height || 1);
|
|
237
|
+
const translateX = targetBBox.x + targetBBox.width / 2 - (sourceBBox.x + sourceBBox.width / 2);
|
|
238
|
+
const translateY = targetBBox.y + targetBBox.height / 2 - (sourceBBox.y + sourceBBox.height / 2);
|
|
239
|
+
const originX = sourceBBox.x + sourceBBox.width / 2;
|
|
240
|
+
const originY = sourceBBox.y + sourceBBox.height / 2;
|
|
241
|
+
gsap2.set(sourceElement, {
|
|
242
|
+
transformOrigin: `${originX}px ${originY}px`
|
|
243
|
+
});
|
|
244
|
+
timeline.add(sourceElement, {
|
|
245
|
+
scaleX,
|
|
246
|
+
scaleY,
|
|
247
|
+
x: translateX,
|
|
248
|
+
y: translateY,
|
|
249
|
+
duration,
|
|
250
|
+
ease: getGSAPEasing(easing),
|
|
251
|
+
delay,
|
|
252
|
+
onComplete: () => {
|
|
253
|
+
sourceElement.remove();
|
|
254
|
+
gsap2.set(targetElement, { opacity: 1 });
|
|
255
|
+
}
|
|
256
|
+
}, startTime);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function ReplacementTransform(source, target, options = {}) {
|
|
261
|
+
const { duration = 1, easing = "easeInOut", delay = 0, replace = true } = options;
|
|
262
|
+
return {
|
|
263
|
+
duration,
|
|
264
|
+
target: source,
|
|
265
|
+
execute(scene, timeline, startTime) {
|
|
266
|
+
var _a, _b;
|
|
267
|
+
const sourceElement = scene.getElement(source);
|
|
268
|
+
const targetElement = scene.getOrCreateElement(target);
|
|
269
|
+
if (!sourceElement || !targetElement) return;
|
|
270
|
+
gsap2.set(targetElement, { opacity: 0, visibility: "hidden" });
|
|
271
|
+
const sourceBBox = ((_a = sourceElement.getBBox) == null ? void 0 : _a.call(sourceElement)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
272
|
+
const targetBBox = ((_b = targetElement.getBBox) == null ? void 0 : _b.call(targetElement)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
273
|
+
const scaleX = targetBBox.width / (sourceBBox.width || 1);
|
|
274
|
+
const scaleY = targetBBox.height / (sourceBBox.height || 1);
|
|
275
|
+
const sourceCenterX = sourceBBox.x + sourceBBox.width / 2;
|
|
276
|
+
const sourceCenterY = sourceBBox.y + sourceBBox.height / 2;
|
|
277
|
+
const targetCenterX = targetBBox.x + targetBBox.width / 2;
|
|
278
|
+
const targetCenterY = targetBBox.y + targetBBox.height / 2;
|
|
279
|
+
timeline.add(sourceElement, {
|
|
280
|
+
transformOrigin: `${sourceCenterX}px ${sourceCenterY}px`,
|
|
281
|
+
scaleX,
|
|
282
|
+
scaleY,
|
|
283
|
+
x: targetCenterX - sourceCenterX,
|
|
284
|
+
y: targetCenterY - sourceCenterY,
|
|
285
|
+
opacity: 0,
|
|
286
|
+
duration,
|
|
287
|
+
ease: getGSAPEasing(easing),
|
|
288
|
+
delay,
|
|
289
|
+
onComplete: () => {
|
|
290
|
+
if (replace) {
|
|
291
|
+
sourceElement.remove();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}, startTime);
|
|
295
|
+
timeline.add(targetElement, {
|
|
296
|
+
visibility: "visible",
|
|
297
|
+
opacity: 1,
|
|
298
|
+
duration: duration * 0.5,
|
|
299
|
+
ease: "power2.out",
|
|
300
|
+
delay: delay + duration * 0.5
|
|
301
|
+
}, startTime);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function MoveToTarget(target, options = {}) {
|
|
306
|
+
const { duration = 1, easing = "easeInOut", delay = 0 } = options;
|
|
307
|
+
return {
|
|
308
|
+
duration,
|
|
309
|
+
target,
|
|
310
|
+
execute(scene, timeline, startTime) {
|
|
311
|
+
const element = scene.getElement(target);
|
|
312
|
+
if (!element) return;
|
|
313
|
+
const targetState = target._targetState;
|
|
314
|
+
if (targetState) {
|
|
315
|
+
timeline.add(element, __spreadProps(__spreadValues({}, targetState), {
|
|
316
|
+
duration,
|
|
317
|
+
ease: getGSAPEasing(easing),
|
|
318
|
+
delay
|
|
319
|
+
}), startTime);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function Morphing(source, target, options = {}) {
|
|
325
|
+
const { duration = 1, easing = "easeInOut", delay = 0 } = options;
|
|
326
|
+
return {
|
|
327
|
+
duration,
|
|
328
|
+
target: source,
|
|
329
|
+
execute(scene, timeline, startTime) {
|
|
330
|
+
var _a;
|
|
331
|
+
const sourceElement = scene.getElement(source);
|
|
332
|
+
const targetElement = scene.getOrCreateElement(target);
|
|
333
|
+
if (!sourceElement || !targetElement) return;
|
|
334
|
+
const sourcePath = sourceElement.querySelector("path") || sourceElement;
|
|
335
|
+
const targetPath = targetElement.querySelector("path") || targetElement;
|
|
336
|
+
gsap2.set(targetElement, { opacity: 0 });
|
|
337
|
+
if ((_a = gsap2.plugins) == null ? void 0 : _a.morphSVG) {
|
|
338
|
+
const targetD = targetPath.getAttribute("d");
|
|
339
|
+
if (targetD) {
|
|
340
|
+
timeline.add(sourcePath, {
|
|
341
|
+
morphSVG: targetD,
|
|
342
|
+
duration,
|
|
343
|
+
ease: getGSAPEasing(easing),
|
|
344
|
+
delay,
|
|
345
|
+
onComplete: () => {
|
|
346
|
+
sourceElement.remove();
|
|
347
|
+
gsap2.set(targetElement, { opacity: 1 });
|
|
348
|
+
}
|
|
349
|
+
}, startTime);
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
Transform(source, target, options).execute(scene, timeline, startTime);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function TransformMatchingShapes(source, target, options = {}) {
|
|
358
|
+
const { duration = 1, easing = "easeInOut", delay = 0 } = options;
|
|
359
|
+
return {
|
|
360
|
+
duration,
|
|
361
|
+
target: source,
|
|
362
|
+
execute(scene, timeline, startTime) {
|
|
363
|
+
var _a, _b;
|
|
364
|
+
const sourceElement = scene.getElement(source);
|
|
365
|
+
const targetElement = scene.getOrCreateElement(target);
|
|
366
|
+
if (!sourceElement || !targetElement) return;
|
|
367
|
+
const sourceChildren = Array.from(sourceElement.children);
|
|
368
|
+
const targetChildren = Array.from(targetElement.children);
|
|
369
|
+
gsap2.set(targetElement, { opacity: 0 });
|
|
370
|
+
const pairs = Math.min(sourceChildren.length, targetChildren.length);
|
|
371
|
+
for (let i = 0; i < pairs; i++) {
|
|
372
|
+
const sourceChild = sourceChildren[i];
|
|
373
|
+
const targetChild = targetChildren[i];
|
|
374
|
+
const sourceBBox = ((_a = sourceChild.getBBox) == null ? void 0 : _a.call(sourceChild)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
375
|
+
const targetBBox = ((_b = targetChild.getBBox) == null ? void 0 : _b.call(targetChild)) || { x: 0, y: 0, width: 0, height: 0 };
|
|
376
|
+
const scaleX = targetBBox.width / (sourceBBox.width || 1);
|
|
377
|
+
const scaleY = targetBBox.height / (sourceBBox.height || 1);
|
|
378
|
+
const translateX = targetBBox.x - sourceBBox.x;
|
|
379
|
+
const translateY = targetBBox.y - sourceBBox.y;
|
|
380
|
+
timeline.add(sourceChild, {
|
|
381
|
+
scaleX,
|
|
382
|
+
scaleY,
|
|
383
|
+
x: translateX,
|
|
384
|
+
y: translateY,
|
|
385
|
+
duration,
|
|
386
|
+
ease: getGSAPEasing(easing),
|
|
387
|
+
delay
|
|
388
|
+
}, startTime);
|
|
389
|
+
}
|
|
390
|
+
for (let i = pairs; i < sourceChildren.length; i++) {
|
|
391
|
+
const child = sourceChildren[i];
|
|
392
|
+
if (child) {
|
|
393
|
+
timeline.add(child, {
|
|
394
|
+
opacity: 0,
|
|
395
|
+
duration: duration * 0.5,
|
|
396
|
+
ease: "power2.in"
|
|
397
|
+
}, startTime);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
timeline.call(() => {
|
|
401
|
+
sourceElement.remove();
|
|
402
|
+
gsap2.set(targetElement, { opacity: 1 });
|
|
403
|
+
}, startTime + duration);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export {
|
|
409
|
+
__spreadValues,
|
|
410
|
+
__spreadProps,
|
|
411
|
+
__objRest,
|
|
412
|
+
Timeline,
|
|
413
|
+
createTimeline,
|
|
414
|
+
easingMap,
|
|
415
|
+
getGSAPEasing,
|
|
416
|
+
Transform,
|
|
417
|
+
ReplacementTransform,
|
|
418
|
+
MoveToTarget,
|
|
419
|
+
Morphing,
|
|
420
|
+
TransformMatchingShapes
|
|
421
|
+
};
|