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/jsr.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@chuchi/chnobli",
3
+ "version": "0.1.12",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./src/chnobli.ts",
7
+ "./easing": "./src/timing/easing.ts",
8
+ "./utils": "./src/utils/utils.ts",
9
+ "./scroll": "./src/scroll/index.ts",
10
+ "./animator": "./src/animator/index.ts"
11
+ },
12
+ "publish": {
13
+ "include": ["src", "LICENSE.md"],
14
+ "exclude": ["src/tests"]
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chnobli",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "author": "Sören Meier <info@soerenmeier.ch>",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,12 +9,13 @@
9
9
  "lint": "eslint ./src",
10
10
  "test": "node --expose-gc ../node_modules/.bin/vitest run",
11
11
  "test:watch": "node --expose-gc ../node_modules/.bin/vitest",
12
+ "check-jsr": "jsr publish --dry-run",
12
13
  "build": "tsc -p tsconfig.build.json",
13
14
  "watch": "tsc -w -p tsconfig.build.json"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
17
- "url": "https://github.com/soerenmeier/chnobli.git"
18
+ "url": "https://github.com/chuchi-dev/chnobli.git"
18
19
  },
19
20
  "license": "MIT",
20
21
  "exports": {
@@ -30,17 +31,24 @@
30
31
  "import": "./dist/scroll/index.js",
31
32
  "types": "./dist/scroll/index.d.ts"
32
33
  },
34
+ "./animator": {
35
+ "import": "./dist/animator/index.js",
36
+ "types": "./dist/animator/index.d.ts"
37
+ },
33
38
  ".": {
34
39
  "import": "./dist/chnobli.js",
35
40
  "types": "./dist/chnobli.d.ts"
36
41
  }
37
42
  },
38
43
  "devDependencies": {
39
- "eslint": "^8.45.0",
44
+ "@eslint/js": "^9.4.0",
45
+ "@types/eslint__js": "^8.42.3",
46
+ "eslint": "^8.57.0",
40
47
  "jsdoc": "^4.0.2",
41
48
  "prettier": "^3.2.4",
42
49
  "tslib": "^2.6.2",
43
- "typescript": "^5.1.6",
50
+ "typescript": "^5.4.5",
51
+ "typescript-eslint": "^7.11.0",
44
52
  "vitest": "^1.1.3"
45
53
  },
46
54
  "dependencies": {
@@ -7,6 +7,7 @@ import Timing, {
7
7
  import Property, { ParseableValue, newProperty } from '../property/Property.js';
8
8
  import Ticker from '../timing/Ticker.js';
9
9
  import { Target } from '../target/Target.js';
10
+ import { DestroyOptions } from '../timeline/public.js';
10
11
 
11
12
  export default class Animation {
12
13
  timing: Timing;
@@ -95,9 +96,11 @@ export default class Animation {
95
96
  }
96
97
  }
97
98
 
98
- destroy() {
99
- for (const prop of this._props) {
100
- prop.restoreBefore(this.target);
99
+ destroy(opts: DestroyOptions) {
100
+ if (!opts.keepValues) {
101
+ for (const prop of this._props) {
102
+ prop.restoreBefore(this.target);
103
+ }
101
104
  }
102
105
 
103
106
  this._ticker.unregisterTarget(this.target.inner());
@@ -0,0 +1,130 @@
1
+ import Property, { newProperty } from '../property/Property.js';
2
+ import { Target } from '../target/Target.js';
3
+ import Ticker from '../timing/Ticker.js';
4
+ import Timing, { STATE_AFTER } from '../timing/Timing.js';
5
+
6
+ export type Settings = {
7
+ duration: number;
8
+ ease?: (t: number) => number;
9
+ };
10
+
11
+ /*
12
+
13
+ const opacity = animator(obj, {
14
+ duration: 200,
15
+ ease: sinInOut
16
+ });
17
+
18
+ opacity.set({ opacity: 0 });
19
+
20
+ opacity.to({ opacity: 1 });
21
+ opacity.to({ opacity: 2 }, 1000);
22
+ */
23
+
24
+ export default class Animator {
25
+ setts: Settings;
26
+ target: Target;
27
+ private props: Map<string, PropertyAnimator<any>>;
28
+
29
+ private ticker: Ticker;
30
+
31
+ constructor(target: any, ticker: Ticker, setts: Settings) {
32
+ this.setts = setts;
33
+ this.target = ticker.registerTarget(target);
34
+
35
+ this.ticker = ticker;
36
+
37
+ this.props = new Map();
38
+ }
39
+
40
+ private getProp(name: string): PropertyAnimator<any> {
41
+ const prop = this.props.get(name);
42
+ if (prop) return prop;
43
+
44
+ const newProp = new PropertyAnimator(name, this.setts, this.target);
45
+ this.props.set(name, newProp);
46
+ return newProp;
47
+ }
48
+
49
+ set(props: Record<string, any>) {
50
+ for (const prop in props) {
51
+ const propAni = this.getProp(prop);
52
+ console.log('got prop ani', propAni);
53
+ propAni.set(this.target, props[prop]);
54
+ console.log('got prop ani', propAni);
55
+ }
56
+ }
57
+
58
+ to(props: Record<string, any>, duration?: number) {
59
+ for (const prop in props) {
60
+ const propAni = this.getProp(prop);
61
+ propAni.to(this.target, props[prop], duration);
62
+ }
63
+ }
64
+
65
+ /// returns if the ticker should keep running
66
+ _tick(change: number): boolean {
67
+ let shouldStop = true;
68
+
69
+ for (const prop of this.props.values()) {
70
+ prop.advance(change);
71
+ prop.render(this.target);
72
+
73
+ if (prop.timing.state < STATE_AFTER) {
74
+ shouldStop = false;
75
+ }
76
+ }
77
+
78
+ return !shouldStop;
79
+ }
80
+ }
81
+
82
+ export class PropertyAnimator<V> {
83
+ prop: Property<V>;
84
+ timing: Timing;
85
+
86
+ private initialized: boolean;
87
+
88
+ constructor(prop: string, setts: Settings, target: Target) {
89
+ this.prop = newProperty(prop, target.type());
90
+
91
+ this.timing = new Timing(setts);
92
+ this.initialized = false;
93
+ }
94
+
95
+ set(target: Target, value: any) {
96
+ const val = this.prop.parseValue(value);
97
+
98
+ this.prop.init(target, val, val);
99
+
100
+ this.timing.seek(2);
101
+ }
102
+
103
+ to(target: Target, value: any, duration?: number) {
104
+ const val = this.prop.parseValue(value);
105
+
106
+ let current = null;
107
+ if (this.initialized) {
108
+ current = this.prop.interpolate(this.timing.position);
109
+ }
110
+
111
+ this.prop.init(target, current, val);
112
+ this.initialized = true;
113
+
114
+ this.timing.seek(0);
115
+ if (typeof duration === 'number') {
116
+ this.timing.setDuration(duration);
117
+ }
118
+ }
119
+
120
+ advance(change: number) {
121
+ this.timing.advance(change);
122
+ }
123
+
124
+ // call advance first
125
+ render(target: Target) {
126
+ const pos = this.timing.position;
127
+
128
+ this.prop.setValue(target, this.prop.interpolate(pos));
129
+ }
130
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+
3
+ const obj = { opacity: 1 };
4
+ // maybe we could even have stagger?
5
+ const opacity = animator(obj, {
6
+ // initial value
7
+ // might also be able to be set with stagger?
8
+ // for example
9
+ opacity: 1,
10
+
11
+ duration: 200,
12
+ ease: sineInOut
13
+ });
14
+
15
+ // or maybe instead
16
+
17
+ const animator = animator();
18
+ animator.add(obj, {
19
+ opacity: 1,
20
+ duration: 200,
21
+ ease: sineInOut
22
+ });
23
+
24
+ // what is the reason why we would wan't one animator with
25
+ // multiple objects with different timings
26
+ // could we not just use multiple animators
27
+
28
+
29
+ opacity.set(obj, { opacity: 0 });
30
+
31
+ let's make the most basic animator first
32
+
33
+
34
+ const opacity = animator(obj, {
35
+ duration: 200,
36
+ ease: sinInOut
37
+ });
38
+
39
+ opacity.set({ opacity: 0 });
40
+
41
+ opacity.to({ opacity: 1 });
42
+ opacity.to({ opacity: 2 }, 1000);
43
+
44
+
45
+
46
+
47
+ */
48
+
49
+ import Animator, { AnimatorProps } from './public.js';
50
+
51
+ export { Animator };
52
+ export type { AnimatorProps };
53
+
54
+ export function animator(target: any, props?: AnimatorProps): Animator {
55
+ return new Animator(target, props);
56
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ set,
3
+ to,
4
+ */
5
+
6
+ import AnimationFrameTicker from '../timing/AnimationFrameTicker.js';
7
+ import Ticker from '../timing/Ticker.js';
8
+ import Events from '../utils/Events.js';
9
+ import Animator from './Animator.js';
10
+
11
+ export type AnimatorProps = {
12
+ duration?: number;
13
+ ease?: (t: number) => number;
14
+ };
15
+
16
+ export default class PublicAnimator {
17
+ private ticker: Ticker;
18
+ private inner: Animator;
19
+ private runningTicker: any;
20
+ private events: Events;
21
+
22
+ constructor(target: any, props: AnimatorProps = {}) {
23
+ this.ticker = AnimationFrameTicker.global();
24
+ this.inner = new Animator(target, this.ticker, {
25
+ duration: props.duration ?? 1000,
26
+ ease: props.ease,
27
+ });
28
+ this.events = new Events();
29
+ }
30
+
31
+ set(props: Record<string, any>): this {
32
+ this.inner.set(props);
33
+ this.startTicker();
34
+
35
+ return this;
36
+ }
37
+
38
+ to(props: Record<string, any>, duration?: number): this {
39
+ this.inner.to(props, duration);
40
+ this.startTicker();
41
+
42
+ return this;
43
+ }
44
+
45
+ // on: update
46
+ on(ev: string, fn: (...args: any[]) => void): () => void {
47
+ return this.events.add(ev, fn);
48
+ }
49
+
50
+ private startTicker() {
51
+ if (this.runningTicker) return;
52
+
53
+ this.runningTicker = this.ticker.add((change, opts) => {
54
+ const keepRunning = this.inner._tick(change);
55
+
56
+ opts.onApplied(() => {
57
+ this.events.trigger('update');
58
+ });
59
+
60
+ if (!keepRunning) {
61
+ opts.remove();
62
+ this.runningTicker = null;
63
+ }
64
+ });
65
+ }
66
+ }
package/src/chnobli.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import Animation, { AnimationProps } from './animation/public.js';
2
- import Timeline from './timeline/public.js';
2
+ import Timeline, { TimelineProps } from './timeline/public.js';
3
3
  import Stagger, { type StaggerValue } from './stagger/stagger.js';
4
4
  import type { Targets, AnimationTarget } from './target/Target.js';
5
5
 
6
6
  export type {
7
7
  Animation,
8
8
  Timeline,
9
+ TimelineProps,
9
10
  Stagger,
10
11
  Targets,
11
12
  AnimationTarget,
@@ -28,7 +29,7 @@ export function animate(
28
29
  return new Animation(targets, props);
29
30
  }
30
31
 
31
- export function timeline(props: Record<string, any> = {}): Timeline {
32
+ export function timeline(props: TimelineProps = {}): Timeline {
32
33
  return new Timeline(props);
33
34
  }
34
35
 
@@ -77,7 +77,7 @@ export default class ClassProperty implements Property<string[], Interpolated> {
77
77
  * and in reverse add it at pos 1
78
78
  */
79
79
 
80
- let obj: Interpolated = {
80
+ const obj: Interpolated = {
81
81
  add: [],
82
82
  remove: [],
83
83
  };
@@ -1,5 +1,5 @@
1
1
  import Value from '../values/Value.js';
2
- import Property, { ParseableValue } from './Property.js';
2
+ import Property from './Property.js';
3
3
  import { Target } from '../target/Target.js';
4
4
 
5
5
  export type XYValue = {