chnobli 0.1.10 → 0.1.12
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.md +21 -0
- package/dist/animation/Animation.d.ts +2 -1
- package/dist/animation/Animation.d.ts.map +1 -1
- package/dist/animation/Animation.js +5 -3
- package/dist/animation/Animation.js.map +1 -1
- package/dist/animator/Animator.d.ts +30 -0
- package/dist/animator/Animator.d.ts.map +1 -0
- package/dist/animator/Animator.js +97 -0
- package/dist/animator/Animator.js.map +1 -0
- package/dist/animator/index.d.ts +5 -0
- package/dist/animator/index.d.ts.map +1 -0
- package/dist/animator/index.js +53 -0
- package/dist/animator/index.js.map +1 -0
- package/dist/animator/public.d.ts +16 -0
- package/dist/animator/public.d.ts.map +1 -0
- package/dist/animator/public.js +50 -0
- package/dist/animator/public.js.map +1 -0
- package/dist/chnobli.d.ts +3 -3
- package/dist/chnobli.d.ts.map +1 -1
- package/dist/chnobli.js.map +1 -1
- package/dist/property/ClassProperty.js +1 -1
- package/dist/property/ClassProperty.js.map +1 -1
- package/dist/property/TransformXYProperty.d.ts.map +1 -1
- package/dist/scroll/Scroll.d.ts +24 -3
- package/dist/scroll/Scroll.d.ts.map +1 -1
- package/dist/scroll/Scroll.js +157 -43
- package/dist/scroll/Scroll.js.map +1 -1
- package/dist/scroll/ScrollEvent.d.ts.map +1 -1
- package/dist/scroll/ScrollEvent.js +1 -0
- package/dist/scroll/ScrollEvent.js.map +1 -1
- package/dist/scroll/index.d.ts +2 -0
- package/dist/scroll/index.d.ts.map +1 -1
- package/dist/scroll/index.js +1 -0
- package/dist/scroll/index.js.map +1 -1
- package/dist/scroll/public.d.ts +19 -1
- package/dist/scroll/public.d.ts.map +1 -1
- package/dist/scroll/public.js +26 -1
- package/dist/scroll/public.js.map +1 -1
- package/dist/target/DomTarget.js +1 -1
- package/dist/target/DomTarget.js.map +1 -1
- package/dist/target/ObjectTarget.d.ts +11 -10
- package/dist/target/ObjectTarget.d.ts.map +1 -1
- package/dist/target/ObjectTarget.js +20 -13
- package/dist/target/ObjectTarget.js.map +1 -1
- package/dist/target/TestDomNode.d.ts.map +1 -1
- package/dist/timeline/Timeline.d.ts +2 -1
- package/dist/timeline/Timeline.d.ts.map +1 -1
- package/dist/timeline/Timeline.js +4 -4
- package/dist/timeline/Timeline.js.map +1 -1
- package/dist/timeline/public.d.ts +11 -4
- package/dist/timeline/public.d.ts.map +1 -1
- package/dist/timeline/public.js +19 -11
- package/dist/timeline/public.js.map +1 -1
- package/dist/timing/AnimationFrameTicker.d.ts.map +1 -1
- package/dist/timing/AnimationFrameTicker.js +5 -1
- package/dist/timing/AnimationFrameTicker.js.map +1 -1
- package/dist/timing/TestTicker.d.ts.map +1 -1
- package/dist/timing/TestTicker.js +5 -1
- package/dist/timing/TestTicker.js.map +1 -1
- package/dist/timing/Ticker.d.ts +4 -2
- package/dist/timing/Ticker.d.ts.map +1 -1
- package/dist/timing/Timing.d.ts +47 -2
- package/dist/timing/Timing.d.ts.map +1 -1
- package/dist/timing/Timing.js +118 -84
- package/dist/timing/Timing.js.map +1 -1
- package/dist/timing/easing.d.ts +1 -2
- package/dist/timing/easing.d.ts.map +1 -1
- package/dist/timing/easing.js.map +1 -1
- package/dist/utils/Events.js +1 -1
- package/dist/utils/Events.js.map +1 -1
- package/dist/utils/motionpath.js +5 -5
- package/dist/utils/motionpath.js.map +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +0 -8
- package/dist/utils/utils.js.map +1 -1
- package/dist/values/ColorValue.d.ts.map +1 -1
- package/dist/values/ColorValue.js +1 -0
- package/dist/values/ColorValue.js.map +1 -1
- package/dist/values/StyleValue.d.ts.map +1 -1
- package/dist/values/Value.d.ts.map +1 -1
- package/dist/values/Value.js +1 -1
- package/dist/values/Value.js.map +1 -1
- package/eslint.config.js +23 -0
- package/jsr.json +16 -0
- package/package.json +12 -4
- package/src/animation/Animation.ts +6 -3
- package/src/animator/Animator.ts +130 -0
- package/src/animator/index.ts +56 -0
- package/src/animator/public.ts +66 -0
- package/src/chnobli.ts +3 -2
- package/src/property/ClassProperty.ts +1 -1
- package/src/property/TransformXYProperty.ts +1 -1
- package/src/scroll/Scroll.ts +204 -51
- package/src/scroll/ScrollEvent.ts +1 -0
- package/src/scroll/index.ts +3 -0
- package/src/scroll/public.ts +35 -2
- package/src/target/DomTarget.ts +1 -1
- package/src/target/ObjectTarget.ts +19 -13
- package/src/target/TestDomNode.ts +3 -3
- package/src/tests/properties.test.ts +86 -3
- package/src/tests/scroll.test.ts +36 -0
- package/src/tests/timeline.test.ts +1 -1
- package/src/tests/timing.test.ts +32 -0
- package/src/tests/usecases.test.ts +40 -2
- package/src/tests/values.test.ts +9 -9
- package/src/timeline/Timeline.ts +5 -4
- package/src/timeline/public.ts +34 -12
- package/src/timing/AnimationFrameTicker.ts +6 -1
- package/src/timing/TestTicker.ts +7 -1
- package/src/timing/Ticker.ts +5 -1
- package/src/timing/Timing.ts +133 -97
- package/src/timing/easing.ts +6 -1
- package/src/utils/Events.ts +1 -1
- package/src/utils/motionpath.ts +5 -5
- package/src/utils/utils.ts +13 -16
- package/src/values/ColorValue.ts +5 -4
- package/src/values/StyleValue.ts +4 -4
- package/src/values/Value.ts +8 -8
- package/.eslintrc.cjs +0 -39
- package/src/animator.js +0 -187
package/src/animator.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/* eslint no-unused-vars: 0 */
|
|
2
|
-
|
|
3
|
-
import { quadInOut, quadOut } from './easing/index.js';
|
|
4
|
-
import { range } from 'fire/util.js';
|
|
5
|
-
|
|
6
|
-
const START = 0;
|
|
7
|
-
const RUNNING = 1;
|
|
8
|
-
const ENDING = 2;
|
|
9
|
-
const ENDED = 3;
|
|
10
|
-
|
|
11
|
-
export default class Animator {
|
|
12
|
-
constructor(el, props) {
|
|
13
|
-
this.el = el;
|
|
14
|
-
|
|
15
|
-
this.running = false;
|
|
16
|
-
|
|
17
|
-
this.props = [];
|
|
18
|
-
|
|
19
|
-
this.prevTime = null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (const propName in props) {
|
|
23
|
-
const prop = new PropertyAnimator(propName, props[propName], el);
|
|
24
|
-
this.props.push(prop);
|
|
25
|
-
this[propName] = prop;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// if the animation loop has not started starts it
|
|
30
|
-
run() {
|
|
31
|
-
// if running
|
|
32
|
-
if (this.prevTime !== null)
|
|
33
|
-
return;
|
|
34
|
-
|
|
35
|
-
requestAnimationFrame(a => this._tick(a));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
_tick(elapsed) {
|
|
39
|
-
if (this.prevTime === null)
|
|
40
|
-
this.prevTime = elapsed;
|
|
41
|
-
|
|
42
|
-
const change = elapsed - this.prevTime;
|
|
43
|
-
this.prevTime = elapsed;
|
|
44
|
-
|
|
45
|
-
const transforms = [];
|
|
46
|
-
const cssVars = [];
|
|
47
|
-
|
|
48
|
-
let stillRunning = false;
|
|
49
|
-
|
|
50
|
-
for (const prop of this.props) {
|
|
51
|
-
prop._tick(change);
|
|
52
|
-
|
|
53
|
-
if (prop.state < ENDED)
|
|
54
|
-
stillRunning = true;
|
|
55
|
-
|
|
56
|
-
if (prop.name === 'translateY' || prop.name === 'scale')
|
|
57
|
-
transforms.push(prop);
|
|
58
|
-
else if (prop.name.startsWith('--'))
|
|
59
|
-
cssVars.push(prop);
|
|
60
|
-
else
|
|
61
|
-
throw new Error('unknown prop ' + prop.name);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!stillRunning) {
|
|
65
|
-
this.prevTime = null;
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (transforms.some(t => t.state < ENDED)) {
|
|
70
|
-
this.el.style.transform = transforms.map(t => {
|
|
71
|
-
const v = t._toTransformValue();
|
|
72
|
-
return v;
|
|
73
|
-
}).join(' ');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
for (const prop of cssVars) {
|
|
77
|
-
if (prop.state < ENDED)
|
|
78
|
-
this.el.style.setProperty(prop.name, prop._toCssValue());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
requestAnimationFrame(a => this._tick(a));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class PropertyAnimator {
|
|
87
|
-
constructor(name, type, el) {
|
|
88
|
-
this.name = name;
|
|
89
|
-
this.type = type;
|
|
90
|
-
|
|
91
|
-
this.fromV = null;
|
|
92
|
-
this.currentV = null;
|
|
93
|
-
this.toV = null;
|
|
94
|
-
|
|
95
|
-
this.easing = quadInOut;
|
|
96
|
-
|
|
97
|
-
this.elapsed = 0;
|
|
98
|
-
this.duration = 0;
|
|
99
|
-
this.state = ENDED;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
set(val) {
|
|
103
|
-
this.fromV = val;
|
|
104
|
-
this.currentV = val;
|
|
105
|
-
this.toV = val;
|
|
106
|
-
|
|
107
|
-
this.elapsed = 0;
|
|
108
|
-
this.duration = 0;
|
|
109
|
-
this.state = START;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
to(val, dur = null) {
|
|
113
|
-
this.fromV = this.currentV;
|
|
114
|
-
this.toV = val;
|
|
115
|
-
|
|
116
|
-
if (this.state === RUNNING)
|
|
117
|
-
this.easing = quadOut;
|
|
118
|
-
else
|
|
119
|
-
this.easing = quadInOut;
|
|
120
|
-
|
|
121
|
-
this.elapsed = 0;
|
|
122
|
-
this.duration = dur ?? 500;
|
|
123
|
-
this.state = START;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
_tick(change) {
|
|
127
|
-
if (this.state >= ENDING)
|
|
128
|
-
return this.state = ENDED;
|
|
129
|
-
|
|
130
|
-
this.elapsed += change;
|
|
131
|
-
|
|
132
|
-
const dur = Math.max(this.duration, 1);
|
|
133
|
-
const t = Math.min(this.elapsed / dur, 1);
|
|
134
|
-
if (t >= 1)
|
|
135
|
-
this.state = ENDED;
|
|
136
|
-
else
|
|
137
|
-
this.state = RUNNING;
|
|
138
|
-
|
|
139
|
-
const et = this.easing(t);
|
|
140
|
-
|
|
141
|
-
if (this.type === 'num') {
|
|
142
|
-
const dif = this.toV - this.fromV;
|
|
143
|
-
this.currentV = this.fromV + dif * et;
|
|
144
|
-
} else if (this.type === 'hex') {
|
|
145
|
-
if (!Array.isArray(this.fromV))
|
|
146
|
-
this.fromV = hexToRgb(this.fromV);
|
|
147
|
-
if (!Array.isArray(this.toV))
|
|
148
|
-
this.toV = hexToRgb(this.toV);
|
|
149
|
-
|
|
150
|
-
// now animate
|
|
151
|
-
this.currentV = this.fromV.map((from, i) => {
|
|
152
|
-
return from + (this.toV[i] - from) * et;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
_toTransformValue() {
|
|
158
|
-
let v = this.currentV;
|
|
159
|
-
if (this.name === 'translateY')
|
|
160
|
-
v += 'px';
|
|
161
|
-
|
|
162
|
-
return `${this.name}(${v})`;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_toCssValue() {
|
|
166
|
-
if (this.type === 'hex')
|
|
167
|
-
return `rgba(${this.currentV.map(v => Math.round(v)).join()}, 1)`;
|
|
168
|
-
throw new Error('to css value');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
function hexToRgb(val) {
|
|
174
|
-
if (!val.startsWith('#') || val.length !== 7)
|
|
175
|
-
throw new Error('expected a hex value with 6 characters');
|
|
176
|
-
|
|
177
|
-
const hex = val.substring(1);
|
|
178
|
-
|
|
179
|
-
const values = range(0, 3)
|
|
180
|
-
.map(i => parseInt(hex.substring(i * 2, i * 2 + 2), 16));
|
|
181
|
-
|
|
182
|
-
return values;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// function rgbToHex(rgb) {
|
|
186
|
-
// return
|
|
187
|
-
// }
|