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.
Files changed (120) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/animation/Animation.d.ts +2 -1
  3. package/dist/animation/Animation.d.ts.map +1 -1
  4. package/dist/animation/Animation.js +5 -3
  5. package/dist/animation/Animation.js.map +1 -1
  6. package/dist/animator/Animator.d.ts +30 -0
  7. package/dist/animator/Animator.d.ts.map +1 -0
  8. package/dist/animator/Animator.js +97 -0
  9. package/dist/animator/Animator.js.map +1 -0
  10. package/dist/animator/index.d.ts +5 -0
  11. package/dist/animator/index.d.ts.map +1 -0
  12. package/dist/animator/index.js +53 -0
  13. package/dist/animator/index.js.map +1 -0
  14. package/dist/animator/public.d.ts +16 -0
  15. package/dist/animator/public.d.ts.map +1 -0
  16. package/dist/animator/public.js +50 -0
  17. package/dist/animator/public.js.map +1 -0
  18. package/dist/chnobli.d.ts +3 -3
  19. package/dist/chnobli.d.ts.map +1 -1
  20. package/dist/chnobli.js.map +1 -1
  21. package/dist/property/ClassProperty.js +1 -1
  22. package/dist/property/ClassProperty.js.map +1 -1
  23. package/dist/property/TransformXYProperty.d.ts.map +1 -1
  24. package/dist/scroll/Scroll.d.ts +24 -3
  25. package/dist/scroll/Scroll.d.ts.map +1 -1
  26. package/dist/scroll/Scroll.js +157 -43
  27. package/dist/scroll/Scroll.js.map +1 -1
  28. package/dist/scroll/ScrollEvent.d.ts.map +1 -1
  29. package/dist/scroll/ScrollEvent.js +1 -0
  30. package/dist/scroll/ScrollEvent.js.map +1 -1
  31. package/dist/scroll/index.d.ts +2 -0
  32. package/dist/scroll/index.d.ts.map +1 -1
  33. package/dist/scroll/index.js +1 -0
  34. package/dist/scroll/index.js.map +1 -1
  35. package/dist/scroll/public.d.ts +19 -1
  36. package/dist/scroll/public.d.ts.map +1 -1
  37. package/dist/scroll/public.js +26 -1
  38. package/dist/scroll/public.js.map +1 -1
  39. package/dist/target/DomTarget.js +1 -1
  40. package/dist/target/DomTarget.js.map +1 -1
  41. package/dist/target/ObjectTarget.d.ts +11 -10
  42. package/dist/target/ObjectTarget.d.ts.map +1 -1
  43. package/dist/target/ObjectTarget.js +20 -13
  44. package/dist/target/ObjectTarget.js.map +1 -1
  45. package/dist/target/TestDomNode.d.ts.map +1 -1
  46. package/dist/timeline/Timeline.d.ts +2 -1
  47. package/dist/timeline/Timeline.d.ts.map +1 -1
  48. package/dist/timeline/Timeline.js +4 -4
  49. package/dist/timeline/Timeline.js.map +1 -1
  50. package/dist/timeline/public.d.ts +11 -4
  51. package/dist/timeline/public.d.ts.map +1 -1
  52. package/dist/timeline/public.js +19 -11
  53. package/dist/timeline/public.js.map +1 -1
  54. package/dist/timing/AnimationFrameTicker.d.ts.map +1 -1
  55. package/dist/timing/AnimationFrameTicker.js +5 -1
  56. package/dist/timing/AnimationFrameTicker.js.map +1 -1
  57. package/dist/timing/TestTicker.d.ts.map +1 -1
  58. package/dist/timing/TestTicker.js +5 -1
  59. package/dist/timing/TestTicker.js.map +1 -1
  60. package/dist/timing/Ticker.d.ts +4 -2
  61. package/dist/timing/Ticker.d.ts.map +1 -1
  62. package/dist/timing/Timing.d.ts +47 -2
  63. package/dist/timing/Timing.d.ts.map +1 -1
  64. package/dist/timing/Timing.js +118 -84
  65. package/dist/timing/Timing.js.map +1 -1
  66. package/dist/timing/easing.d.ts +1 -2
  67. package/dist/timing/easing.d.ts.map +1 -1
  68. package/dist/timing/easing.js.map +1 -1
  69. package/dist/utils/Events.js +1 -1
  70. package/dist/utils/Events.js.map +1 -1
  71. package/dist/utils/motionpath.js +5 -5
  72. package/dist/utils/motionpath.js.map +1 -1
  73. package/dist/utils/utils.d.ts.map +1 -1
  74. package/dist/utils/utils.js +0 -8
  75. package/dist/utils/utils.js.map +1 -1
  76. package/dist/values/ColorValue.d.ts.map +1 -1
  77. package/dist/values/ColorValue.js +1 -0
  78. package/dist/values/ColorValue.js.map +1 -1
  79. package/dist/values/StyleValue.d.ts.map +1 -1
  80. package/dist/values/Value.d.ts.map +1 -1
  81. package/dist/values/Value.js +1 -1
  82. package/dist/values/Value.js.map +1 -1
  83. package/eslint.config.js +23 -0
  84. package/jsr.json +16 -0
  85. package/package.json +12 -4
  86. package/src/animation/Animation.ts +6 -3
  87. package/src/animator/Animator.ts +130 -0
  88. package/src/animator/index.ts +56 -0
  89. package/src/animator/public.ts +66 -0
  90. package/src/chnobli.ts +3 -2
  91. package/src/property/ClassProperty.ts +1 -1
  92. package/src/property/TransformXYProperty.ts +1 -1
  93. package/src/scroll/Scroll.ts +204 -51
  94. package/src/scroll/ScrollEvent.ts +1 -0
  95. package/src/scroll/index.ts +3 -0
  96. package/src/scroll/public.ts +35 -2
  97. package/src/target/DomTarget.ts +1 -1
  98. package/src/target/ObjectTarget.ts +19 -13
  99. package/src/target/TestDomNode.ts +3 -3
  100. package/src/tests/properties.test.ts +86 -3
  101. package/src/tests/scroll.test.ts +36 -0
  102. package/src/tests/timeline.test.ts +1 -1
  103. package/src/tests/timing.test.ts +32 -0
  104. package/src/tests/usecases.test.ts +40 -2
  105. package/src/tests/values.test.ts +9 -9
  106. package/src/timeline/Timeline.ts +5 -4
  107. package/src/timeline/public.ts +34 -12
  108. package/src/timing/AnimationFrameTicker.ts +6 -1
  109. package/src/timing/TestTicker.ts +7 -1
  110. package/src/timing/Ticker.ts +5 -1
  111. package/src/timing/Timing.ts +133 -97
  112. package/src/timing/easing.ts +6 -1
  113. package/src/utils/Events.ts +1 -1
  114. package/src/utils/motionpath.ts +5 -5
  115. package/src/utils/utils.ts +13 -16
  116. package/src/values/ColorValue.ts +5 -4
  117. package/src/values/StyleValue.ts +4 -4
  118. package/src/values/Value.ts +8 -8
  119. package/.eslintrc.cjs +0 -39
  120. 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
- // }