cseen 0.0.0-stage → 0.2.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 +169 -2
- package/dist/all.d.ts +9 -0
- package/dist/all.js +11 -0
- package/dist/all.js.map +1 -0
- package/dist/anim/mount.d.ts +69 -0
- package/dist/anim/mount.js +234 -0
- package/dist/anim/mount.js.map +1 -0
- package/dist/anim/orbit.d.ts +85 -0
- package/dist/anim/orbit.js +198 -0
- package/dist/anim/orbit.js.map +1 -0
- package/dist/anim/timeline.d.ts +287 -0
- package/dist/anim/timeline.js +379 -0
- package/dist/anim/timeline.js.map +1 -0
- package/dist/charts/charts.d.ts +216 -0
- package/dist/charts/charts.js +570 -0
- package/dist/charts/charts.js.map +1 -0
- package/dist/charts/index.d.ts +2 -0
- package/dist/charts/index.js +2 -0
- package/dist/charts/index.js.map +1 -0
- package/dist/construct/construct.d.ts +73 -0
- package/dist/construct/construct.js +96 -0
- package/dist/construct/construct.js.map +1 -0
- package/dist/construct/geom.d.ts +91 -0
- package/dist/construct/geom.js +118 -0
- package/dist/construct/geom.js.map +1 -0
- package/dist/core/animatable.d.ts +19 -0
- package/dist/core/animatable.js +41 -0
- package/dist/core/animatable.js.map +1 -0
- package/dist/core/camera.d.ts +48 -0
- package/dist/core/camera.js +95 -0
- package/dist/core/camera.js.map +1 -0
- package/dist/core/math.d.ts +39 -0
- package/dist/core/math.js +104 -0
- package/dist/core/math.js.map +1 -0
- package/dist/core/nodes.d.ts +387 -0
- package/dist/core/nodes.js +418 -0
- package/dist/core/nodes.js.map +1 -0
- package/dist/core/render.d.ts +98 -0
- package/dist/core/render.js +386 -0
- package/dist/core/render.js.map +1 -0
- package/dist/core/scene.d.ts +96 -0
- package/dist/core/scene.js +104 -0
- package/dist/core/scene.js.map +1 -0
- package/dist/core/sort.d.ts +40 -0
- package/dist/core/sort.js +181 -0
- package/dist/core/sort.js.map +1 -0
- package/dist/core/split.d.ts +47 -0
- package/dist/core/split.js +169 -0
- package/dist/core/split.js.map +1 -0
- package/dist/core/svg-import.d.ts +16 -0
- package/dist/core/svg-import.js +53 -0
- package/dist/core/svg-import.js.map +1 -0
- package/dist/cseen.css +106 -0
- package/dist/devices/devices.d.ts +307 -0
- package/dist/devices/devices.js +327 -0
- package/dist/devices/devices.js.map +1 -0
- package/dist/devices/index.d.ts +6 -0
- package/dist/devices/index.js +4 -0
- package/dist/devices/index.js.map +1 -0
- package/dist/devices/keyboard.d.ts +86 -0
- package/dist/devices/keyboard.js +186 -0
- package/dist/devices/keyboard.js.map +1 -0
- package/dist/devices/peripherals.d.ts +103 -0
- package/dist/devices/peripherals.js +171 -0
- package/dist/devices/peripherals.js.map +1 -0
- package/dist/draw/heads.d.ts +11 -0
- package/dist/draw/heads.js +26 -0
- package/dist/draw/heads.js.map +1 -0
- package/dist/draw/link.d.ts +76 -0
- package/dist/draw/link.js +102 -0
- package/dist/draw/link.js.map +1 -0
- package/dist/draw/overlap.d.ts +50 -0
- package/dist/draw/overlap.js +80 -0
- package/dist/draw/overlap.js.map +1 -0
- package/dist/draw/pen.d.ts +41 -0
- package/dist/draw/pen.js +57 -0
- package/dist/draw/pen.js.map +1 -0
- package/dist/draw/shapes.d.ts +206 -0
- package/dist/draw/shapes.js +225 -0
- package/dist/draw/shapes.js.map +1 -0
- package/dist/draw/svgplane.d.ts +74 -0
- package/dist/draw/svgplane.js +97 -0
- package/dist/draw/svgplane.js.map +1 -0
- package/dist/draw/text.d.ts +111 -0
- package/dist/draw/text.js +204 -0
- package/dist/draw/text.js.map +1 -0
- package/dist/draw/words.d.ts +29 -0
- package/dist/draw/words.js +30 -0
- package/dist/draw/words.js.map +1 -0
- package/dist/flow/flow.d.ts +206 -0
- package/dist/flow/flow.js +408 -0
- package/dist/flow/flow.js.map +1 -0
- package/dist/flow/index.d.ts +4 -0
- package/dist/flow/index.js +3 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/flow/layout.d.ts +66 -0
- package/dist/flow/layout.js +353 -0
- package/dist/flow/layout.js.map +1 -0
- package/dist/flow/sequence.d.ts +114 -0
- package/dist/flow/sequence.js +309 -0
- package/dist/flow/sequence.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.js +2 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/math.d.ts +238 -0
- package/dist/math/math.js +421 -0
- package/dist/math/math.js.map +1 -0
- package/dist/optics/index.d.ts +2 -0
- package/dist/optics/index.js +2 -0
- package/dist/optics/index.js.map +1 -0
- package/dist/optics/optics.d.ts +94 -0
- package/dist/optics/optics.js +173 -0
- package/dist/optics/optics.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/ui.d.ts +166 -0
- package/dist/ui/ui.js +255 -0
- package/dist/ui/ui.js.map +1 -0
- package/dist/uml/factory.d.ts +15 -0
- package/dist/uml/factory.js +16 -0
- package/dist/uml/factory.js.map +1 -0
- package/dist/uml/index.d.ts +3 -0
- package/dist/uml/index.js +3 -0
- package/dist/uml/index.js.map +1 -0
- package/dist/uml/uml.d.ts +187 -0
- package/dist/uml/uml.js +599 -0
- package/dist/uml/uml.js.map +1 -0
- package/dist/waves/index.d.ts +2 -0
- package/dist/waves/index.js +2 -0
- package/dist/waves/index.js.map +1 -0
- package/dist/waves/waves.d.ts +93 -0
- package/dist/waves/waves.js +206 -0
- package/dist/waves/waves.js.map +1 -0
- package/package.json +85 -4
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { rad } from "../core/math.js";
|
|
2
|
+
/** Default pitch limits in degrees. */
|
|
3
|
+
const PITCH = [-89, 90];
|
|
4
|
+
/** Default zoom limits. */
|
|
5
|
+
const ZOOM = [0.4, 6];
|
|
6
|
+
/** `v` held inside `[lo, hi]`. */
|
|
7
|
+
const clampTo = (v, [lo, hi]) => Math.min(Math.max(v, lo), hi);
|
|
8
|
+
/**
|
|
9
|
+
* New angles after a drag of (dx, dy) pixels, in degrees. Dragging right turns the scene so its
|
|
10
|
+
* near side moves right; dragging down tips the top towards the viewer. Pitch is clamped.
|
|
11
|
+
*/
|
|
12
|
+
export function dragToAngles(a, dx, dy, o = {}) {
|
|
13
|
+
const k = o.sensitivity ?? 0.4, l = o.limits ?? {};
|
|
14
|
+
const yaw = a.yaw + dx * k;
|
|
15
|
+
return { yaw: l.yaw ? clampTo(yaw, l.yaw) : yaw, pitch: clampTo(a.pitch + dy * k, l.pitch ?? PITCH) };
|
|
16
|
+
}
|
|
17
|
+
/** Multiplies a zoom by a factor and keeps it inside the limits. */
|
|
18
|
+
export function clampZoom(zoom, factor, range = ZOOM) {
|
|
19
|
+
return clampTo(zoom * factor, range);
|
|
20
|
+
}
|
|
21
|
+
/** Where a perspective camera sits when it looks at `target` from `distance` along the given angles (same angles as the parallel camera). */
|
|
22
|
+
export function orbitPosition(target, yaw, pitch, distance) {
|
|
23
|
+
const y = rad(yaw), p = rad(pitch);
|
|
24
|
+
return [target[0] - distance * Math.sin(y) * Math.cos(p), target[1] - distance * Math.cos(y) * Math.cos(p), target[2] + distance * Math.sin(p)];
|
|
25
|
+
}
|
|
26
|
+
/** The angles and distance of a perspective camera, the inverse of `orbitPosition`. */
|
|
27
|
+
export function anglesOf(position, target) {
|
|
28
|
+
const v = [target[0] - position[0], target[1] - position[1], target[2] - position[2]];
|
|
29
|
+
const distance = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
30
|
+
return { yaw: (Math.atan2(v[0], v[1]) * 180) / Math.PI, pitch: (Math.asin(Math.max(-1, Math.min(1, -v[2] / distance))) * 180) / Math.PI, distance };
|
|
31
|
+
}
|
|
32
|
+
/** Reads the current angles from either kind of camera. */
|
|
33
|
+
export function readAngles(cam) {
|
|
34
|
+
if (cam.kind === 'ortho')
|
|
35
|
+
return { yaw: cam.props.yaw, pitch: cam.props.pitch };
|
|
36
|
+
const a = anglesOf(cam.props.position, cam.props.target);
|
|
37
|
+
return { yaw: a.yaw, pitch: a.pitch };
|
|
38
|
+
}
|
|
39
|
+
/** Points a camera along new angles. A perspective camera keeps its target and distance. */
|
|
40
|
+
export function writeAngles(cam, yaw, pitch) {
|
|
41
|
+
if (cam.kind === 'ortho') {
|
|
42
|
+
cam.set('yaw', yaw);
|
|
43
|
+
cam.set('pitch', pitch);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const target = cam.props.target, d = anglesOf(cam.props.position, target).distance;
|
|
47
|
+
cam.set('position', orbitPosition(target, yaw, pitch, d));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Turns the camera of a scene with the pointer, wheel, touch and keyboard. The scene needs
|
|
51
|
+
* `fit: 'sphere'` (or a locked fit) so the object keeps its size while it turns.
|
|
52
|
+
*
|
|
53
|
+
* const player = mount(el, scene, { timeline });
|
|
54
|
+
* orbit(el, scene, { onChange: () => player.invalidate() });
|
|
55
|
+
*
|
|
56
|
+
* If a timeline animates the camera, the timeline wins while it plays.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
60
|
+
* s.add(ground(), box({ at: [0, 0, 0], size: 1.5, role: 'accent' }));
|
|
61
|
+
*
|
|
62
|
+
* const el = document.querySelector('#figure')!;
|
|
63
|
+
* const player = mount(el, s);
|
|
64
|
+
* orbit(el.querySelector('svg')!, s, { onChange: () => player.invalidate() }); // drag, wheel, pinch and arrow keys
|
|
65
|
+
*/
|
|
66
|
+
export function orbit(target, scene, o = {}) {
|
|
67
|
+
const cam = scene.camera, el = target;
|
|
68
|
+
const limits = o.limits ?? {}, zr = limits.zoom ?? ZOOM, zoomOn = o.zoom ?? true, keys = o.keyboard ?? true;
|
|
69
|
+
const sens = o.sensitivity ?? 0.4, start = o.home ?? cam.snapshot();
|
|
70
|
+
const changed = () => o.onChange?.();
|
|
71
|
+
/** turns the camera as if dragged by (dx, dy) pixels */
|
|
72
|
+
const turn = (dx, dy) => {
|
|
73
|
+
const a = dragToAngles(readAngles(cam), dx, dy, { sensitivity: sens, limits });
|
|
74
|
+
writeAngles(cam, a.yaw, a.pitch);
|
|
75
|
+
changed();
|
|
76
|
+
};
|
|
77
|
+
const zoomBy = (f) => { cam.set('zoom', clampZoom(cam.zoom, f, zr)); changed(); };
|
|
78
|
+
const reset = () => { cam.restore(start); changed(); };
|
|
79
|
+
const prev = { touchAction: el.style.touchAction, cursor: el.style.cursor, tabindex: el.getAttribute('tabindex') };
|
|
80
|
+
el.style.touchAction = 'none';
|
|
81
|
+
el.style.cursor = 'grab';
|
|
82
|
+
if (keys && prev.tabindex === null)
|
|
83
|
+
el.setAttribute('tabindex', '0');
|
|
84
|
+
const pts = new Map();
|
|
85
|
+
let pinch = 0, idleUntil = 0;
|
|
86
|
+
/** notes that the person is interacting, so auto-rotate waits 2.5 s */
|
|
87
|
+
const touch = () => { idleUntil = performance.now() + 2500; };
|
|
88
|
+
/** distance in pixels between the first two pointers (for pinch) */
|
|
89
|
+
const gap = () => { const [a, b] = [...pts.values()]; return Math.hypot(a.x - b.x, a.y - b.y); };
|
|
90
|
+
const down = (e) => {
|
|
91
|
+
if (e.button > 0)
|
|
92
|
+
return;
|
|
93
|
+
if (e.target?.closest?.('.cn-link'))
|
|
94
|
+
return; // capturing the pointer would swallow the click
|
|
95
|
+
el.setPointerCapture?.(e.pointerId);
|
|
96
|
+
pts.set(e.pointerId, { x: e.clientX, y: e.clientY });
|
|
97
|
+
if (pts.size === 2)
|
|
98
|
+
pinch = gap();
|
|
99
|
+
el.style.cursor = 'grabbing';
|
|
100
|
+
touch();
|
|
101
|
+
};
|
|
102
|
+
const move = (e) => {
|
|
103
|
+
const p = pts.get(e.pointerId);
|
|
104
|
+
if (!p)
|
|
105
|
+
return;
|
|
106
|
+
const dx = e.clientX - p.x, dy = e.clientY - p.y;
|
|
107
|
+
p.x = e.clientX;
|
|
108
|
+
p.y = e.clientY;
|
|
109
|
+
if (pts.size === 1)
|
|
110
|
+
turn(dx, dy);
|
|
111
|
+
else if (pts.size === 2 && zoomOn) {
|
|
112
|
+
const g = gap();
|
|
113
|
+
if (pinch > 0 && g > 0)
|
|
114
|
+
zoomBy(g / pinch);
|
|
115
|
+
pinch = g;
|
|
116
|
+
}
|
|
117
|
+
touch();
|
|
118
|
+
};
|
|
119
|
+
const up = (e) => {
|
|
120
|
+
pts.delete(e.pointerId);
|
|
121
|
+
pinch = pts.size === 2 ? gap() : 0;
|
|
122
|
+
if (!pts.size)
|
|
123
|
+
el.style.cursor = 'grab';
|
|
124
|
+
};
|
|
125
|
+
const wheel = (e) => {
|
|
126
|
+
if (!zoomOn)
|
|
127
|
+
return;
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
zoomBy(Math.exp(-e.deltaY * 0.0015));
|
|
130
|
+
touch();
|
|
131
|
+
};
|
|
132
|
+
/** keyboard control: arrows turn, plus/minus zoom, 0 or Home resets */
|
|
133
|
+
const key = (e) => {
|
|
134
|
+
if (e.altKey || e.ctrlKey || e.metaKey)
|
|
135
|
+
return;
|
|
136
|
+
const step = (e.shiftKey ? 15 : 5) / sens; // degrees, as pixels of drag
|
|
137
|
+
const k = e.key;
|
|
138
|
+
if (k === 'ArrowLeft')
|
|
139
|
+
turn(-step, 0);
|
|
140
|
+
else if (k === 'ArrowRight')
|
|
141
|
+
turn(step, 0);
|
|
142
|
+
else if (k === 'ArrowUp')
|
|
143
|
+
turn(0, -step);
|
|
144
|
+
else if (k === 'ArrowDown')
|
|
145
|
+
turn(0, step);
|
|
146
|
+
else if (zoomOn && (k === '+' || k === '='))
|
|
147
|
+
zoomBy(1.2);
|
|
148
|
+
else if (zoomOn && (k === '-' || k === '_'))
|
|
149
|
+
zoomBy(1 / 1.2);
|
|
150
|
+
else if (k === '0' || k === 'Home')
|
|
151
|
+
reset();
|
|
152
|
+
else
|
|
153
|
+
return;
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
touch();
|
|
156
|
+
};
|
|
157
|
+
el.addEventListener('pointerdown', down);
|
|
158
|
+
el.addEventListener('pointermove', move);
|
|
159
|
+
el.addEventListener('pointerup', up);
|
|
160
|
+
el.addEventListener('pointercancel', up);
|
|
161
|
+
el.addEventListener('dblclick', reset);
|
|
162
|
+
el.addEventListener('wheel', wheel, { passive: false });
|
|
163
|
+
if (keys)
|
|
164
|
+
el.addEventListener('keydown', key);
|
|
165
|
+
let raf = 0, lastT = 0;
|
|
166
|
+
const reduce = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
167
|
+
/** auto-rotate frame; the step is capped so a background tab does not jump when it wakes */
|
|
168
|
+
const spin = (now) => {
|
|
169
|
+
raf = requestAnimationFrame(spin);
|
|
170
|
+
const dt = lastT ? Math.min((now - lastT) / 1000, 0.1) : 0;
|
|
171
|
+
lastT = now;
|
|
172
|
+
if (pts.size || performance.now() < idleUntil || !dt)
|
|
173
|
+
return;
|
|
174
|
+
const a = readAngles(cam);
|
|
175
|
+
writeAngles(cam, a.yaw + o.autoRotate * dt, a.pitch);
|
|
176
|
+
changed();
|
|
177
|
+
};
|
|
178
|
+
if (o.autoRotate && !reduce)
|
|
179
|
+
raf = requestAnimationFrame(spin);
|
|
180
|
+
return {
|
|
181
|
+
reset,
|
|
182
|
+
destroy() {
|
|
183
|
+
cancelAnimationFrame(raf);
|
|
184
|
+
el.removeEventListener('pointerdown', down);
|
|
185
|
+
el.removeEventListener('pointermove', move);
|
|
186
|
+
el.removeEventListener('pointerup', up);
|
|
187
|
+
el.removeEventListener('pointercancel', up);
|
|
188
|
+
el.removeEventListener('dblclick', reset);
|
|
189
|
+
el.removeEventListener('wheel', wheel);
|
|
190
|
+
el.removeEventListener('keydown', key);
|
|
191
|
+
el.style.touchAction = prev.touchAction;
|
|
192
|
+
el.style.cursor = prev.cursor;
|
|
193
|
+
if (keys && prev.tabindex === null)
|
|
194
|
+
el.removeAttribute('tabindex');
|
|
195
|
+
},
|
|
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,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { type Animatable, type Value } from '../core/animatable.ts';
|
|
2
|
+
import { type V3 } from '../core/math.ts';
|
|
3
|
+
import type { Node } from '../core/nodes.ts';
|
|
4
|
+
import type { Scene } from '../core/scene.ts';
|
|
5
|
+
/** An easing function: maps progress 0 to 1 onto progress 0 to 1. */
|
|
6
|
+
export type Ease = (t: number) => number;
|
|
7
|
+
/** The named easing curves: `linear`, `in`, `out`, `inOut`, `smooth` and `back`. Each maps time 0 to 1 onto progress 0 to 1. */
|
|
8
|
+
export declare const ease: {
|
|
9
|
+
linear: (t: number) => number;
|
|
10
|
+
in: (t: number) => number;
|
|
11
|
+
out: (t: number) => number;
|
|
12
|
+
inOut: (t: number) => number;
|
|
13
|
+
smooth: (t: number) => number;
|
|
14
|
+
back: (t: number) => number;
|
|
15
|
+
};
|
|
16
|
+
/** The name of a built-in easing curve. */
|
|
17
|
+
export type EaseName = keyof typeof ease;
|
|
18
|
+
type To = Value | ((current: Value) => Value);
|
|
19
|
+
/** One change of one object's properties over a span of time. */
|
|
20
|
+
export interface Tween {
|
|
21
|
+
/** the animated object */
|
|
22
|
+
target: Animatable;
|
|
23
|
+
/** the values to reach, or functions of the current value */
|
|
24
|
+
to: Record<string, To>;
|
|
25
|
+
/** values set before the tween starts, so something can wait invisible until its moment */
|
|
26
|
+
from?: Record<string, Value>;
|
|
27
|
+
/** start time in seconds, relative to its animation */
|
|
28
|
+
start: number;
|
|
29
|
+
/** length in seconds */
|
|
30
|
+
duration: number;
|
|
31
|
+
/** the easing function */
|
|
32
|
+
ease: Ease;
|
|
33
|
+
}
|
|
34
|
+
/** A piece of animation. It knows its length and its tweens (starting at 0), and can be combined with others. */
|
|
35
|
+
export interface Anim {
|
|
36
|
+
/** length in seconds */
|
|
37
|
+
duration: number;
|
|
38
|
+
/** the tweens that make it up, with start times relative to its beginning */
|
|
39
|
+
tweens: Tween[];
|
|
40
|
+
}
|
|
41
|
+
/** Options of `tween`. */
|
|
42
|
+
export interface TweenOpts {
|
|
43
|
+
/** length in seconds, 1 by default */
|
|
44
|
+
duration?: number;
|
|
45
|
+
/** an easing name or function, `inOut` by default */
|
|
46
|
+
ease?: EaseName | Ease;
|
|
47
|
+
/** values set before the tween starts */
|
|
48
|
+
from?: Record<string, Value>;
|
|
49
|
+
/** seconds to wait before it starts */
|
|
50
|
+
delay?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Animate any properties of a node or camera: `tween(cube, { opacity: 0.2, pos: [1, 0, 0] })`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
57
|
+
* s.add(ground());
|
|
58
|
+
* const b = s.add(box({ at: [-2, 0, 0], size: 1.2, role: 'accent' }));
|
|
59
|
+
*
|
|
60
|
+
* const tl = new Timeline();
|
|
61
|
+
* tl.play(tween(b, { pos: [2, 0, 0], rot: [0, 0, 90] }, { duration: 1.6, ease: 'inOut' }));
|
|
62
|
+
* tl.lockFit(s);
|
|
63
|
+
*/
|
|
64
|
+
export declare function tween(target: Animatable, to: Record<string, To>, o?: TweenOpts): Anim;
|
|
65
|
+
/**
|
|
66
|
+
* Fades a node in from invisible to its own opacity.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
70
|
+
* s.add(ground());
|
|
71
|
+
* const b = s.add(box({ at: [0, 0, 0], size: 1.5, role: 'accent' }));
|
|
72
|
+
*
|
|
73
|
+
* const tl = new Timeline();
|
|
74
|
+
* tl.play(fadeIn(b, 1));
|
|
75
|
+
* tl.lockFit(s);
|
|
76
|
+
*/
|
|
77
|
+
export declare const fadeIn: (n: Node, duration?: number) => Anim;
|
|
78
|
+
/**
|
|
79
|
+
* Fades a node out to invisible.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
83
|
+
* s.add(ground());
|
|
84
|
+
* const b = s.add(box({ at: [0, 0, 0], size: 1.5, role: 'accent' }));
|
|
85
|
+
*
|
|
86
|
+
* const tl = new Timeline();
|
|
87
|
+
* tl.play(wait(0.5));
|
|
88
|
+
* tl.play(fadeOut(b, 1));
|
|
89
|
+
* tl.lockFit(s);
|
|
90
|
+
*/
|
|
91
|
+
export declare const fadeOut: (n: Node, duration?: number) => Anim;
|
|
92
|
+
/**
|
|
93
|
+
* Draws a line, curve or outline on from its start to its end.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
97
|
+
* s.add(ground());
|
|
98
|
+
* const a = s.add(arrow([-3, 0, 0], [3, 0, 2], { role: 'accent' }));
|
|
99
|
+
*
|
|
100
|
+
* const tl = new Timeline();
|
|
101
|
+
* tl.play(draw(a, 1.2));
|
|
102
|
+
* tl.lockFit(s);
|
|
103
|
+
*/
|
|
104
|
+
export declare const draw: (n: Node, duration?: number) => Anim;
|
|
105
|
+
/**
|
|
106
|
+
* Moves a node to a point.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
110
|
+
* s.add(ground());
|
|
111
|
+
* const b = s.add(box({ at: [-3, 0, 0], size: 1.2, role: 'accent' }));
|
|
112
|
+
*
|
|
113
|
+
* const tl = new Timeline();
|
|
114
|
+
* tl.play(moveTo(b, [3, 0, 0], 1.5));
|
|
115
|
+
* tl.lockFit(s);
|
|
116
|
+
*/
|
|
117
|
+
export declare const moveTo: (n: Node, pos: V3, duration?: number, ease?: EaseName) => Anim;
|
|
118
|
+
/**
|
|
119
|
+
* Moves a node by an offset from where it is when the animation starts.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
123
|
+
* s.add(ground());
|
|
124
|
+
* const b = s.add(box({ at: [-2, 0, 0], size: 1.2, role: 'accent' }));
|
|
125
|
+
*
|
|
126
|
+
* const tl = new Timeline();
|
|
127
|
+
* tl.play(moveBy(b, [4, 0, 0], 1.5));
|
|
128
|
+
* tl.lockFit(s);
|
|
129
|
+
*/
|
|
130
|
+
export declare const moveBy: (n: Node, by: V3, duration?: number, ease?: EaseName) => Anim;
|
|
131
|
+
/**
|
|
132
|
+
* Rotates a node to Euler angles in degrees about x, y and z.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
136
|
+
* s.add(ground());
|
|
137
|
+
* const b = s.add(box({ at: [0, 0, 0], size: [2, 1, 1], role: 'accent' }));
|
|
138
|
+
*
|
|
139
|
+
* const tl = new Timeline();
|
|
140
|
+
* tl.play(rotateTo(b, [0, 0, 90], 1.5));
|
|
141
|
+
* tl.lockFit(s);
|
|
142
|
+
*/
|
|
143
|
+
export declare const rotateTo: (n: Node, rot: V3, duration?: number) => Anim;
|
|
144
|
+
/**
|
|
145
|
+
* Scales a node to a factor.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
149
|
+
* s.add(ground());
|
|
150
|
+
* const b = s.add(box({ at: [0, 0, 0], size: 1, role: 'accent' }));
|
|
151
|
+
*
|
|
152
|
+
* const tl = new Timeline();
|
|
153
|
+
* tl.play(scaleTo(b, 2, 1.2));
|
|
154
|
+
* tl.lockFit(s);
|
|
155
|
+
*/
|
|
156
|
+
export declare const scaleTo: (n: Node, scale: number, duration?: number) => Anim;
|
|
157
|
+
/**
|
|
158
|
+
* Types text or code onto a plane letter by letter.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* const s = new Scene({ view: 'front' });
|
|
162
|
+
* const t = s.add(write('Typed, letter by letter.', { at: [-3, 0, 0], size: [6, 1], fontSize: 0.5 }));
|
|
163
|
+
*
|
|
164
|
+
* const tl = new Timeline();
|
|
165
|
+
* tl.play(typeOn(t, 2));
|
|
166
|
+
* tl.lockFit(s);
|
|
167
|
+
*/
|
|
168
|
+
export declare const typeOn: (n: Node, duration?: number) => Anim;
|
|
169
|
+
/**
|
|
170
|
+
* Does nothing for a while. Use it to leave a gap between two animations.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
174
|
+
* s.add(ground());
|
|
175
|
+
* const b = s.add(box({ at: [0, 0, 0], size: 1.2, role: 'accent' }));
|
|
176
|
+
*
|
|
177
|
+
* const tl = new Timeline();
|
|
178
|
+
* tl.play(wait(1)); // nothing happens for a second
|
|
179
|
+
* tl.play(moveBy(b, [2, 0, 0], 1));
|
|
180
|
+
* tl.lockFit(s);
|
|
181
|
+
*/
|
|
182
|
+
export declare const wait: (duration: number) => Anim;
|
|
183
|
+
/**
|
|
184
|
+
* Plays the animations one after another.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
188
|
+
* s.add(ground());
|
|
189
|
+
* const b = s.add(box({ at: [-2, 0, 0], size: 1.2, role: 'accent' }));
|
|
190
|
+
*
|
|
191
|
+
* const tl = new Timeline();
|
|
192
|
+
* tl.play(seq(moveBy(b, [4, 0, 0], 1), moveBy(b, [0, 3, 0], 1))); // one, then the other
|
|
193
|
+
* tl.lockFit(s);
|
|
194
|
+
*/
|
|
195
|
+
export declare function seq(...anims: Anim[]): Anim;
|
|
196
|
+
/**
|
|
197
|
+
* Plays the animations at the same time.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
201
|
+
* s.add(ground());
|
|
202
|
+
* const b = s.add(box({ at: [-2, 0, 0], size: 1.2, role: 'accent' }));
|
|
203
|
+
*
|
|
204
|
+
* const tl = new Timeline();
|
|
205
|
+
* tl.play(par(moveBy(b, [4, 0, 0], 1.5), rotateTo(b, [0, 0, 90], 1.5))); // both at once
|
|
206
|
+
* tl.lockFit(s);
|
|
207
|
+
*/
|
|
208
|
+
export declare function par(...anims: Anim[]): Anim;
|
|
209
|
+
/**
|
|
210
|
+
* Starts each animation a little after the previous one.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
214
|
+
* s.add(ground());
|
|
215
|
+
* const boxes = [-3, -1, 1, 3].map((x) => s.add(box({ at: [x, 0, 0], size: 1 })));
|
|
216
|
+
*
|
|
217
|
+
* const tl = new Timeline();
|
|
218
|
+
* tl.play(stagger(0.25, ...boxes.map((b) => fadeIn(b, 0.6)))); // each starts a little after the last
|
|
219
|
+
* tl.lockFit(s);
|
|
220
|
+
*/
|
|
221
|
+
export declare function stagger(gap: number, ...anims: Anim[]): Anim;
|
|
222
|
+
/**
|
|
223
|
+
* Plays an animation backwards: every tween runs from its end value to its start value, last one first.
|
|
224
|
+
* Each tween needs a literal `to` and a `from`, so there is something to return to. Put it after the
|
|
225
|
+
* animation to take a construction apart again, or to make a loop that ends where it began.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
229
|
+
* s.add(ground());
|
|
230
|
+
* const b = s.add(box({ at: [-3, 0, 0], size: 1.2, role: 'accent' }));
|
|
231
|
+
*
|
|
232
|
+
* const tl = new Timeline();
|
|
233
|
+
* const there = tween(b, { pos: [3, 0, 0] }, { duration: 1.5, from: { pos: [-3, 0, 0] } });
|
|
234
|
+
* tl.play(there);
|
|
235
|
+
* tl.play(reverse(there));
|
|
236
|
+
* tl.lockFit(s);
|
|
237
|
+
*/
|
|
238
|
+
export declare function reverse(a: Anim): Anim;
|
|
239
|
+
/**
|
|
240
|
+
* A timeline is a list of tweens. `seek(t)` rewinds everything to its starting state and replays up
|
|
241
|
+
* to t, so the result depends only on t. Playing, scrubbing and rendering a still frame all work the same way.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* const s = new Scene({ fit: 'sphere' });
|
|
245
|
+
* s.add(ground());
|
|
246
|
+
* const b = s.add(box({ at: [0, 0, 0], size: 1.5, role: 'accent' }));
|
|
247
|
+
*
|
|
248
|
+
* const tl = new Timeline();
|
|
249
|
+
* tl.play(fadeIn(b, 1));
|
|
250
|
+
* tl.chapter('move').play(moveBy(b, [2, 0, 0], 1.2));
|
|
251
|
+
* tl.lockFit(s);
|
|
252
|
+
*/
|
|
253
|
+
export declare class Timeline {
|
|
254
|
+
/** every tween, with start times on the timeline's clock */
|
|
255
|
+
tweens: Tween[];
|
|
256
|
+
/** named marks, in the order made, for step buttons and captions */
|
|
257
|
+
chapters: {
|
|
258
|
+
name: string;
|
|
259
|
+
time: number;
|
|
260
|
+
}[];
|
|
261
|
+
/** where the next `play` starts: the end of everything so far */
|
|
262
|
+
private cursor;
|
|
263
|
+
/** each animated object with its state before any tween ran, taken lazily and dropped whenever tweens are added */
|
|
264
|
+
private bases;
|
|
265
|
+
/** appends an animation after everything so far */
|
|
266
|
+
play(a: Anim): this;
|
|
267
|
+
/** places an animation at an absolute time without moving the cursor */
|
|
268
|
+
at(time: number, a: Anim): this;
|
|
269
|
+
/** leaves a gap: the next `play` starts `d` seconds later */
|
|
270
|
+
wait(d: number): this;
|
|
271
|
+
/** marks the current time as a named step, for "next step" buttons and captions */
|
|
272
|
+
chapter(name: string): this;
|
|
273
|
+
/** the length in seconds: where the cursor is, so a trailing `wait` counts */
|
|
274
|
+
get duration(): number;
|
|
275
|
+
/** remembers the starting state of every animated object, once */
|
|
276
|
+
private init;
|
|
277
|
+
/** puts every animated object in the state it has at time `t` (seconds) */
|
|
278
|
+
seek(t: number): void;
|
|
279
|
+
/**
|
|
280
|
+
* Fixes the scene's framing to fit every moment of this timeline, so the picture does not
|
|
281
|
+
* shift as things move. Call it once after building the timeline.
|
|
282
|
+
*/
|
|
283
|
+
lockFit(scene: Scene, samples?: number): this;
|
|
284
|
+
/** For `fit: 'sphere'`: one sphere around the scene at every moment, so orbiting a moving scene does not make it breathe. */
|
|
285
|
+
private lockSphere;
|
|
286
|
+
}
|
|
287
|
+
export {};
|