chnobli 0.1.4 → 0.1.6
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/.prettierignore +4 -0
- package/.prettierrc +6 -0
- package/.vscode/settings.json +4 -0
- package/auto-docs/easing.js.html +342 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/auto-docs/global.html +4810 -0
- package/auto-docs/index.html +65 -0
- package/auto-docs/scripts/linenumber.js +25 -0
- package/auto-docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/auto-docs/scripts/prettify/lang-css.js +2 -0
- package/auto-docs/scripts/prettify/prettify.js +28 -0
- package/auto-docs/styles/jsdoc-default.css +358 -0
- package/auto-docs/styles/prettify-jsdoc.css +111 -0
- package/auto-docs/styles/prettify-tomorrow.css +132 -0
- package/dist/animation/Animation.d.ts +36 -0
- package/dist/animation/Animation.d.ts.map +1 -0
- package/dist/animation/Animation.js +230 -0
- package/dist/animation/Animation.js.map +1 -0
- package/dist/animation/animation.d.ts +36 -0
- package/dist/animation/animation.d.ts.map +1 -0
- package/dist/animation/animation.js +230 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/public.d.ts +55 -0
- package/dist/animation/public.d.ts.map +1 -0
- package/dist/animation/public.js +104 -0
- package/dist/animation/public.js.map +1 -0
- package/dist/chnobli.d.ts +15 -0
- package/dist/chnobli.d.ts.map +1 -0
- package/dist/chnobli.js +63 -0
- package/dist/chnobli.js.map +1 -0
- package/dist/property/BasicProperty.d.ts +38 -0
- package/dist/property/BasicProperty.d.ts.map +1 -0
- package/dist/property/BasicProperty.js +72 -0
- package/dist/property/BasicProperty.js.map +1 -0
- package/dist/property/ClassProperty.d.ts +32 -0
- package/dist/property/ClassProperty.d.ts.map +1 -0
- package/dist/property/ClassProperty.js +108 -0
- package/dist/property/ClassProperty.js.map +1 -0
- package/dist/property/Property.d.ts +13 -0
- package/dist/property/Property.d.ts.map +1 -0
- package/dist/property/Property.js +20 -0
- package/dist/property/Property.js.map +1 -0
- package/dist/property/StyleProperty.d.ts +25 -0
- package/dist/property/StyleProperty.d.ts.map +1 -0
- package/dist/property/StyleProperty.js +221 -0
- package/dist/property/StyleProperty.js.map +1 -0
- package/dist/property/TransformProperty.d.ts +15 -0
- package/dist/property/TransformProperty.d.ts.map +1 -0
- package/dist/property/TransformProperty.js +43 -0
- package/dist/property/TransformProperty.js.map +1 -0
- package/dist/property/TransformXYProperty.d.ts +28 -0
- package/dist/property/TransformXYProperty.d.ts.map +1 -0
- package/dist/property/TransformXYProperty.js +65 -0
- package/dist/property/TransformXYProperty.js.map +1 -0
- package/dist/responsive/ResponsiveEvent.d.ts +17 -0
- package/dist/responsive/ResponsiveEvent.d.ts.map +1 -0
- package/dist/responsive/ResponsiveEvent.js +45 -0
- package/dist/responsive/ResponsiveEvent.js.map +1 -0
- package/dist/responsive/TestEvent.d.ts +11 -0
- package/dist/responsive/TestEvent.d.ts.map +1 -0
- package/dist/responsive/TestEvent.js +26 -0
- package/dist/responsive/TestEvent.js.map +1 -0
- package/dist/responsive/event.d.ts +10 -0
- package/dist/responsive/event.d.ts.map +1 -0
- package/dist/responsive/event.js +39 -0
- package/dist/responsive/event.js.map +1 -0
- package/dist/scroll/Scroll.d.ts +27 -0
- package/dist/scroll/Scroll.d.ts.map +1 -0
- package/dist/scroll/Scroll.js +132 -0
- package/dist/scroll/Scroll.js.map +1 -0
- package/dist/scroll/ScrollEvent.d.ts +17 -0
- package/dist/scroll/ScrollEvent.d.ts.map +1 -0
- package/dist/scroll/ScrollEvent.js +39 -0
- package/dist/scroll/ScrollEvent.js.map +1 -0
- package/dist/scroll/public.d.ts +7 -0
- package/dist/scroll/public.d.ts.map +1 -0
- package/dist/scroll/public.js +17 -0
- package/dist/scroll/public.js.map +1 -0
- package/dist/stagger/stagger.d.ts +13 -0
- package/dist/stagger/stagger.d.ts.map +1 -0
- package/dist/stagger/stagger.js +35 -0
- package/dist/stagger/stagger.js.map +1 -0
- package/dist/target/BaseTarget.old.d.ts +33 -0
- package/dist/target/BaseTarget.old.d.ts.map +1 -0
- package/dist/target/BaseTarget.old.js +73 -0
- package/dist/target/BaseTarget.old.js.map +1 -0
- package/dist/target/DomTarget.d.ts +41 -0
- package/dist/target/DomTarget.d.ts.map +1 -0
- package/dist/target/DomTarget.js +230 -0
- package/dist/target/DomTarget.js.map +1 -0
- package/dist/target/Target.d.ts +22 -0
- package/dist/target/Target.d.ts.map +1 -0
- package/dist/target/Target.js +21 -0
- package/dist/target/Target.js.map +1 -0
- package/dist/target/TestDomNode.d.ts +14 -0
- package/dist/target/TestDomNode.d.ts.map +1 -0
- package/dist/target/TestDomNode.js +55 -0
- package/dist/target/TestDomNode.js.map +1 -0
- package/dist/timeline/Nested.d.ts +30 -0
- package/dist/timeline/Nested.d.ts.map +1 -0
- package/dist/timeline/Nested.js +51 -0
- package/dist/timeline/Nested.js.map +1 -0
- package/dist/timeline/TimeLine.d.ts +32 -0
- package/dist/timeline/TimeLine.d.ts.map +1 -0
- package/dist/timeline/TimeLine.js +288 -0
- package/dist/timeline/TimeLine.js.map +1 -0
- package/dist/timeline/public.d.ts +120 -0
- package/dist/timeline/public.d.ts.map +1 -0
- package/dist/timeline/public.js +301 -0
- package/dist/timeline/public.js.map +1 -0
- package/dist/timing/AnimationFrameTicker.d.ts +32 -0
- package/dist/timing/AnimationFrameTicker.d.ts.map +1 -0
- package/dist/timing/AnimationFrameTicker.js +134 -0
- package/dist/timing/AnimationFrameTicker.js.map +1 -0
- package/dist/timing/Ease.d.ts +6 -0
- package/dist/timing/Ease.d.ts.map +1 -0
- package/dist/timing/Ease.js +15 -0
- package/dist/timing/Ease.js.map +1 -0
- package/dist/timing/TestTicker.d.ts +19 -0
- package/dist/timing/TestTicker.d.ts.map +1 -0
- package/dist/timing/TestTicker.js +81 -0
- package/dist/timing/TestTicker.js.map +1 -0
- package/dist/timing/Ticker.d.ts +14 -0
- package/dist/timing/Ticker.d.ts.map +1 -0
- package/dist/timing/Ticker.js +2 -0
- package/dist/timing/Ticker.js.map +1 -0
- package/dist/timing/Timing.d.ts +62 -0
- package/dist/timing/Timing.d.ts.map +1 -0
- package/dist/timing/Timing.js +257 -0
- package/dist/timing/Timing.js.map +1 -0
- package/dist/timing/easing.d.ts +158 -0
- package/dist/timing/easing.d.ts.map +1 -0
- package/dist/timing/easing.js +273 -0
- package/dist/timing/easing.js.map +1 -0
- package/dist/utils/Events.d.ts +9 -0
- package/dist/utils/Events.d.ts.map +1 -0
- package/dist/utils/Events.js +35 -0
- package/dist/utils/Events.js.map +1 -0
- package/dist/utils/internal.d.ts +2 -0
- package/dist/utils/internal.d.ts.map +1 -0
- package/dist/utils/internal.js +6 -0
- package/dist/utils/internal.js.map +1 -0
- package/dist/utils/motionpath.d.ts +16 -0
- package/dist/utils/motionpath.d.ts.map +1 -0
- package/dist/utils/motionpath.js +41 -0
- package/dist/utils/motionpath.js.map +1 -0
- package/dist/utils/utils.d.ts +43 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +93 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/values/ColorValue.d.ts +12 -0
- package/dist/values/ColorValue.d.ts.map +1 -0
- package/dist/values/ColorValue.js +133 -0
- package/dist/values/ColorValue.js.map +1 -0
- package/dist/values/StyleValue.d.ts +40 -0
- package/dist/values/StyleValue.d.ts.map +1 -0
- package/dist/values/StyleValue.js +149 -0
- package/dist/values/StyleValue.js.map +1 -0
- package/dist/values/Value.d.ts +13 -0
- package/dist/values/Value.d.ts.map +1 -0
- package/dist/values/Value.js +38 -0
- package/dist/values/Value.js.map +1 -0
- package/dist/values/defaultcolors.d.ts +2 -0
- package/dist/values/defaultcolors.d.ts.map +1 -0
- package/dist/values/defaultcolors.js +149 -0
- package/dist/values/defaultcolors.js.map +1 -0
- package/package.json +11 -7
- package/src/animation/{animation.js → Animation.ts} +56 -54
- package/src/animation/{public.js → public.ts} +23 -18
- package/src/{chnobli.js → chnobli.ts} +11 -12
- package/src/property/BasicProperty.ts +91 -0
- package/src/property/ClassProperty.ts +132 -0
- package/src/property/Property.ts +33 -0
- package/src/property/StyleProperty.ts +273 -0
- package/src/property/TransformProperty.ts +56 -0
- package/src/property/TransformXYProperty.ts +88 -0
- package/src/responsive/ResponsiveEvent.ts +60 -0
- package/src/responsive/{testevent.js → TestEvent.ts} +12 -10
- package/src/scroll/{scroll.js → Scroll.ts} +53 -35
- package/src/scroll/ScrollEvent.ts +53 -0
- package/src/scroll/public.ts +20 -0
- package/src/stagger/stagger.ts +45 -0
- package/src/target/{basetarget.js → BaseTarget.old.ts} +25 -26
- package/src/target/DomTarget.ts +281 -0
- package/src/target/Target.ts +48 -0
- package/src/target/{testdomnode.js → TestDomNode.ts} +18 -15
- package/src/tests/{properties.test.js → properties.test.ts} +54 -49
- package/src/tests/timeline.test.ts +290 -0
- package/src/tests/{timing.test.js → timing.test.ts} +25 -22
- package/src/tests/{usecases.test.js → usecases.test.ts} +13 -10
- package/src/tests/{values.test.js → values.test.ts} +21 -21
- package/src/timeline/Nested.ts +67 -0
- package/src/timeline/{timeline.js → TimeLine.ts} +126 -56
- package/src/timeline/{public.js → public.ts} +112 -73
- package/src/timing/{ticker.js → AnimationFrameTicker.ts} +36 -21
- package/src/timing/{ease.js → Ease.ts} +6 -5
- package/src/timing/{testticker.js → TestTicker.ts} +27 -24
- package/src/timing/Ticker.ts +11 -0
- package/src/timing/{timing.js → Timing.ts} +72 -63
- package/src/timing/{easing.js → easing.ts} +52 -43
- package/src/utils/{events.js → Events.ts} +12 -11
- package/src/utils/internal.ts +10 -0
- package/src/utils/{motionpath.js → motionpath.ts} +36 -13
- package/src/utils/utils.ts +110 -0
- package/src/values/{colorvalue.js → ColorValue.ts} +46 -47
- package/src/values/StyleValue.ts +186 -0
- package/src/values/{value.js → Value.ts} +14 -12
- package/src/values/{defaultcolors.js → defaultcolors.ts} +2 -2
- package/tsconfig.build.json +19 -0
- package/tsconfig.json +17 -108
- package/src/animation/property.js +0 -556
- package/src/responsive/event.js +0 -46
- package/src/scroll/event.js +0 -41
- package/src/scroll/public.js +0 -17
- package/src/stagger/stagger.js +0 -42
- package/src/target/domtarget.js +0 -266
- package/src/target/target.js +0 -22
- package/src/tests/timeline.test.js +0 -234
- package/src/utils/internal.js +0 -7
- package/src/utils/utils.js +0 -75
- package/src/values/stylevalue.js +0 -148
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import StyleValue from '../values/StyleValue';
|
|
2
|
+
import Property, { ParseableValue } from './Property';
|
|
3
|
+
import Value from '../values/Value';
|
|
4
|
+
import { Target } from '../target/Target';
|
|
5
|
+
import ColorValue, { RGBA } from '../values/ColorValue';
|
|
6
|
+
|
|
7
|
+
export const STYLE_PROPS: Record<string, string | [number, string | null]> = {
|
|
8
|
+
position: 'static',
|
|
9
|
+
display: 'block',
|
|
10
|
+
visibility: 'visible',
|
|
11
|
+
minWidth: 'px',
|
|
12
|
+
width: 'px',
|
|
13
|
+
maxWidth: 'px',
|
|
14
|
+
minHeight: 'px',
|
|
15
|
+
height: 'px',
|
|
16
|
+
maxHeight: 'px',
|
|
17
|
+
top: 'px',
|
|
18
|
+
left: 'px',
|
|
19
|
+
right: 'px',
|
|
20
|
+
bottom: 'px',
|
|
21
|
+
opacity: [1, null],
|
|
22
|
+
padding: 'px',
|
|
23
|
+
margin: 'px',
|
|
24
|
+
color: '#000',
|
|
25
|
+
backgroundColor: '#fff',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default class StyleProperty
|
|
29
|
+
implements Property<StyleValue, StyleValue | null>
|
|
30
|
+
{
|
|
31
|
+
name: string;
|
|
32
|
+
|
|
33
|
+
from: StyleValue | null;
|
|
34
|
+
to: StyleValue | null;
|
|
35
|
+
|
|
36
|
+
unit: string | null;
|
|
37
|
+
|
|
38
|
+
kind: 'text' | 'color' | 'values' | null;
|
|
39
|
+
// if the kind text is set
|
|
40
|
+
// from and to are text
|
|
41
|
+
|
|
42
|
+
private _defaultValue: StyleValue | null;
|
|
43
|
+
|
|
44
|
+
constructor(name: string) {
|
|
45
|
+
this.name = name;
|
|
46
|
+
|
|
47
|
+
this.from = null;
|
|
48
|
+
this.to = null;
|
|
49
|
+
|
|
50
|
+
const def = STYLE_PROPS[name];
|
|
51
|
+
if (Array.isArray(def)) {
|
|
52
|
+
this._defaultValue = new StyleValue([new Value(def[0], def[1])]);
|
|
53
|
+
this.unit = def[1];
|
|
54
|
+
} else if (def === 'px') {
|
|
55
|
+
this._defaultValue = new StyleValue([new Value(0, def)]);
|
|
56
|
+
this.unit = def;
|
|
57
|
+
} else if (typeof def !== 'undefined') {
|
|
58
|
+
this._defaultValue = StyleValue.parse(def);
|
|
59
|
+
this.unit = null;
|
|
60
|
+
} else {
|
|
61
|
+
this._defaultValue = null;
|
|
62
|
+
this.unit = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// text|color|values
|
|
66
|
+
this.kind = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
allowsValueFn(): boolean {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
init(target: Target, from: StyleValue | null, to: StyleValue | null) {
|
|
74
|
+
// this check is probably not necessary?
|
|
75
|
+
if (!from && !to)
|
|
76
|
+
throw new Error('either from or to need to be defined');
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
if the user inputed a text value both need to be treated as text
|
|
80
|
+
and interpolated as classes or in reverse if they are negative values
|
|
81
|
+
|
|
82
|
+
if the user inputed a value both need to be treated as values and need
|
|
83
|
+
to match in length
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
if (from?.kind === 'text' || to?.kind === 'text') {
|
|
87
|
+
if (from && from.kind !== 'text')
|
|
88
|
+
throw new Error('from is expected to be a text because to is');
|
|
89
|
+
|
|
90
|
+
if (to && to.kind !== 'text')
|
|
91
|
+
throw new Error('to is expected to be a text because from is');
|
|
92
|
+
|
|
93
|
+
this.kind = 'text';
|
|
94
|
+
this.from = from;
|
|
95
|
+
this.to = to;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// get the current value
|
|
100
|
+
if (!from) from = this.getValue(target);
|
|
101
|
+
|
|
102
|
+
// get the current value
|
|
103
|
+
if (!to) to = this.getValue(target);
|
|
104
|
+
|
|
105
|
+
if (!from || !to)
|
|
106
|
+
throw new Error(
|
|
107
|
+
'from or to could not be defined, specified ' +
|
|
108
|
+
'it with fromTo',
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// if one is a color both need to be a color
|
|
112
|
+
if (from.kind === 'color' || to.kind === 'color') {
|
|
113
|
+
if (from.kind !== to.kind) throw new Error('expected two colors');
|
|
114
|
+
|
|
115
|
+
this.kind = 'color';
|
|
116
|
+
this.from = from;
|
|
117
|
+
this.to = to;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// check that both are of kind values
|
|
122
|
+
if (from.kind === 'text') from = this.defaultValue()!;
|
|
123
|
+
|
|
124
|
+
if (to.kind === 'text') to = this.defaultValue()!;
|
|
125
|
+
|
|
126
|
+
if (from.length === 0 || to.length === 0)
|
|
127
|
+
throw new Error('from or to has zero values');
|
|
128
|
+
|
|
129
|
+
// at this point from and to are values and both have some values
|
|
130
|
+
|
|
131
|
+
// either from or to needs to be 1 to work
|
|
132
|
+
|
|
133
|
+
if (from.length !== to.length && from.length !== 1 && to.length !== 1)
|
|
134
|
+
throw new Error('from or to need to match in length or be one');
|
|
135
|
+
|
|
136
|
+
const newLength = Math.max(from.length, to.length);
|
|
137
|
+
from.extendToLength(newLength);
|
|
138
|
+
to.extendToLength(newLength);
|
|
139
|
+
|
|
140
|
+
// now let's try to unify each value
|
|
141
|
+
const fromVals = [];
|
|
142
|
+
const toVals = [];
|
|
143
|
+
|
|
144
|
+
// now we need to make sure the values are the same
|
|
145
|
+
for (let i = 0; i < newLength; i++) {
|
|
146
|
+
const f = (from.values as Value[])[i];
|
|
147
|
+
const t = (to.values as Value[])[i];
|
|
148
|
+
|
|
149
|
+
const [nFrom, nTo] = target.unifyValues(this.name, f, t);
|
|
150
|
+
fromVals.push(nFrom);
|
|
151
|
+
toVals.push(nTo);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.kind = 'values';
|
|
155
|
+
this.from = new StyleValue(fromVals);
|
|
156
|
+
this.to = new StyleValue(toVals);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
parseValue(val: ParseableValue): StyleValue {
|
|
160
|
+
return StyleValue.parse(val);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
defaultValue(): StyleValue | null {
|
|
164
|
+
return this._defaultValue?.clone() ?? null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
getValue(target: Target): StyleValue | null {
|
|
168
|
+
const val = target.getStyleValue(this.name);
|
|
169
|
+
if (!val) return this.defaultValue();
|
|
170
|
+
|
|
171
|
+
return val;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interpolate(pos: number): StyleValue | null {
|
|
175
|
+
switch (this.kind) {
|
|
176
|
+
case 'text':
|
|
177
|
+
return this._interpolateText(pos);
|
|
178
|
+
|
|
179
|
+
case 'color':
|
|
180
|
+
return this._interpolateColor(pos);
|
|
181
|
+
|
|
182
|
+
default:
|
|
183
|
+
return this._interpolateValues(pos);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// only call this if kind is text
|
|
188
|
+
private _interpolateText(pos: number): StyleValue | null {
|
|
189
|
+
/*
|
|
190
|
+
## if both values are set
|
|
191
|
+
|
|
192
|
+
<=0 the from value will be set
|
|
193
|
+
>0 the to value will be set
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## if only one text is set
|
|
197
|
+
|
|
198
|
+
if the to value is
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
the text in the to value will be set >0
|
|
202
|
+
the text in the to value will be removed in <=0
|
|
203
|
+
|
|
204
|
+
the text in the from value will be set <1
|
|
205
|
+
the text in the from value will be removed in >=1
|
|
206
|
+
*/
|
|
207
|
+
if (this.from && this.to) {
|
|
208
|
+
if (pos <= 0) return this.from.clone();
|
|
209
|
+
|
|
210
|
+
return this.to.clone();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (this.to) {
|
|
214
|
+
if (pos <= 0) return null;
|
|
215
|
+
|
|
216
|
+
return this.to.clone();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (this.from) {
|
|
220
|
+
if (pos >= 1) return null;
|
|
221
|
+
|
|
222
|
+
return this.from.clone();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
throw new Error('expected from or to');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// only call this if kind is color
|
|
229
|
+
private _interpolateColor(pos: number) {
|
|
230
|
+
const vals = [];
|
|
231
|
+
|
|
232
|
+
for (let i = 0; i < 4; i++) {
|
|
233
|
+
const f = (this.from!.values as ColorValue).values[i];
|
|
234
|
+
const t = (this.to!.values as ColorValue).values[i];
|
|
235
|
+
|
|
236
|
+
const dif = t - f;
|
|
237
|
+
|
|
238
|
+
vals.push(f + pos * dif);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return new StyleValue(new ColorValue(vals as RGBA));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// only call this if kind is values
|
|
245
|
+
// both values should be the same length
|
|
246
|
+
private _interpolateValues(pos: number) {
|
|
247
|
+
const vals = [];
|
|
248
|
+
|
|
249
|
+
const from = this.from!.values as Value[];
|
|
250
|
+
const to = this.to!.values as Value[];
|
|
251
|
+
|
|
252
|
+
for (let i = 0; i < from.length; i++) {
|
|
253
|
+
const f = from[i];
|
|
254
|
+
const t = to[i];
|
|
255
|
+
|
|
256
|
+
const dif = t.num - f.num;
|
|
257
|
+
|
|
258
|
+
vals.push(f.cloneAdd(pos * dif));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return new StyleValue(vals);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
setValue(target: Target, val: StyleValue | null) {
|
|
265
|
+
if (!val) return target.removeStyleValue(this.name);
|
|
266
|
+
|
|
267
|
+
return target.setStyleValue(this.name, val.withDefaultUnit(this.unit));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
removeValue(target: Target) {
|
|
271
|
+
return target.removeStyleValue(this.name);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Value from '../values/Value';
|
|
2
|
+
import BasicProperty from './BasicProperty';
|
|
3
|
+
import { ParseableValue } from './Property';
|
|
4
|
+
import { Target } from '../target/Target';
|
|
5
|
+
|
|
6
|
+
export const TRANSFORM_PROPS: Record<string, [number, string | null]> = {
|
|
7
|
+
x: [0, 'px'],
|
|
8
|
+
y: [0, 'px'],
|
|
9
|
+
z: [0, 'px'],
|
|
10
|
+
scale: [1, null],
|
|
11
|
+
scaleX: [1, null],
|
|
12
|
+
scaleY: [1, null],
|
|
13
|
+
scaleZ: [1, null],
|
|
14
|
+
rotate: [0, 'deg'],
|
|
15
|
+
rotateX: [0, 'deg'],
|
|
16
|
+
rotateY: [0, 'deg'],
|
|
17
|
+
rotateZ: [0, 'deg'],
|
|
18
|
+
skew: [0, 'deg'],
|
|
19
|
+
skewX: [0, 'deg'],
|
|
20
|
+
skewY: [0, 'deg'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default class TransformProperty extends BasicProperty {
|
|
24
|
+
private _defaultValue: Value;
|
|
25
|
+
|
|
26
|
+
constructor(name: string) {
|
|
27
|
+
super(name);
|
|
28
|
+
|
|
29
|
+
this._defaultValue = new Value(...TRANSFORM_PROPS[name]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
parseValue(val: ParseableValue) {
|
|
33
|
+
if (typeof val !== 'string' && typeof val !== 'number')
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Failed to parse value '${val}' for property '${this.name}'`,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return Value.parse(val);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
defaultValue() {
|
|
42
|
+
return this._defaultValue.clone();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getValue(target: Target) {
|
|
46
|
+
return target.getTransformValue(this.name) ?? this.defaultValue();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setValue(target: Target, val: Value) {
|
|
50
|
+
target.setTransformValue(this.name, val);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
removeValue(target: Target) {
|
|
54
|
+
target.removeTransformValue(this.name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Value from '../values/Value';
|
|
2
|
+
import Property, { ParseableValue } from './Property';
|
|
3
|
+
import { Target } from '../target/Target';
|
|
4
|
+
|
|
5
|
+
export type XYValue = {
|
|
6
|
+
x: Value;
|
|
7
|
+
y: Value;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default class TransformXYProperty implements Property<XYValue> {
|
|
11
|
+
name: string;
|
|
12
|
+
|
|
13
|
+
from!: XYValue;
|
|
14
|
+
to!: XYValue;
|
|
15
|
+
|
|
16
|
+
constructor(name: string) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
allowsValueFn(): boolean {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
init(target: Target, from: XYValue | null, to: XYValue | null) {
|
|
25
|
+
if (!from) from = this.getValue(target);
|
|
26
|
+
|
|
27
|
+
if (!to) to = this.getValue(target);
|
|
28
|
+
|
|
29
|
+
if (!from || !to)
|
|
30
|
+
throw new Error('could not determine from or to value');
|
|
31
|
+
|
|
32
|
+
const [fromX, toX] = target.unifyValues('x', from.x, to.x);
|
|
33
|
+
const [fromY, toY] = target.unifyValues('y', from.y, to.y);
|
|
34
|
+
|
|
35
|
+
this.from = { x: fromX, y: fromY };
|
|
36
|
+
this.to = { x: toX, y: toY };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
parseValue(val: any) {
|
|
40
|
+
if (Array.isArray(val)) val = { x: val[0], y: val[1] };
|
|
41
|
+
|
|
42
|
+
const { x, y } = val;
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
x: Value.parse(x),
|
|
46
|
+
y: Value.parse(y),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
defaultValue() {
|
|
51
|
+
return {
|
|
52
|
+
x: new Value(0, 'px'),
|
|
53
|
+
y: new Value(0, 'px'),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getValue(target: Target): XYValue {
|
|
58
|
+
const x = target.getTransformValue('x');
|
|
59
|
+
const y = target.getTransformValue('y');
|
|
60
|
+
|
|
61
|
+
const def = this.defaultValue();
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
x: x ? x : def.x,
|
|
65
|
+
y: y ? y : def.y,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interpolate(pos: number): XYValue {
|
|
70
|
+
const difX = this.to.x.num - this.from.x.num;
|
|
71
|
+
const difY = this.to.y.num - this.from.y.num;
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
x: this.from.x.cloneAdd(pos * difX),
|
|
75
|
+
y: this.from.y.cloneAdd(pos * difY),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setValue(target: Target, val: XYValue) {
|
|
80
|
+
target.setTransformValue('x', val.x.withDefaultUnit('px'));
|
|
81
|
+
target.setTransformValue('y', val.y.withDefaultUnit('px'));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
removeValue(target: Target) {
|
|
85
|
+
target.removeTransformValue('x');
|
|
86
|
+
target.removeTransformValue('y');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type Callback = (
|
|
2
|
+
a: { width: number; height: number },
|
|
3
|
+
b: { remove: () => void },
|
|
4
|
+
) => void;
|
|
5
|
+
|
|
6
|
+
export default class ResponsiveEvent {
|
|
7
|
+
private _listeners: Set<Callback>;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this._listeners = new Set();
|
|
11
|
+
|
|
12
|
+
window.addEventListener('resize', e => this._onResize(e));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static global(): ResponsiveEvent | null {
|
|
16
|
+
// allow to define a test ticker
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
if (typeof globalThis !== 'undefined' && globalThis.chnobliResponsive)
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return globalThis.chnobliResponsive;
|
|
21
|
+
|
|
22
|
+
if (typeof window === 'undefined') return null;
|
|
23
|
+
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
if (typeof window.chnobliResponsive === 'undefined')
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
window.chnobliResponsive = new ResponsiveEvent();
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
return window.chnobliResponsive;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// fn({ width, height }, { remove() })
|
|
33
|
+
add(fn: Callback) {
|
|
34
|
+
this._listeners.add(fn);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
remove: () => {
|
|
38
|
+
this.remove(fn);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
remove(fn: Callback) {
|
|
44
|
+
this._listeners.delete(fn);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_onResize(_e: Event) {
|
|
48
|
+
for (const fn of this._listeners) {
|
|
49
|
+
fn(
|
|
50
|
+
{
|
|
51
|
+
width: window.innerWidth,
|
|
52
|
+
height: window.innerHeight,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
remove: () => this.remove(fn),
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
import { Callback } from './ResponsiveEvent';
|
|
2
|
+
|
|
1
3
|
export default class TestResponsiveEvent {
|
|
4
|
+
private _listeners: Set<Callback>;
|
|
5
|
+
|
|
2
6
|
constructor() {
|
|
3
|
-
this._listeners = new Set;
|
|
7
|
+
this._listeners = new Set();
|
|
4
8
|
|
|
9
|
+
// @ts-ignore
|
|
5
10
|
globalThis.chnobliResponsive = this;
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
// fn({ width, height }, { remove() })
|
|
9
|
-
add(fn) {
|
|
14
|
+
add(fn: Callback) {
|
|
10
15
|
this._listeners.add(fn);
|
|
11
16
|
|
|
12
17
|
return {
|
|
13
18
|
remove: () => {
|
|
14
19
|
this.remove(fn);
|
|
15
|
-
}
|
|
20
|
+
},
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
remove(fn) {
|
|
24
|
+
remove(fn: Callback) {
|
|
20
25
|
this._listeners.delete(fn);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
resize(width, height) {
|
|
28
|
+
resize(width: number, height: number) {
|
|
24
29
|
for (const fn of this._listeners) {
|
|
25
|
-
fn(
|
|
26
|
-
{ width, height },
|
|
27
|
-
{ remove: () => this.remove(fn) }
|
|
28
|
-
);
|
|
30
|
+
fn({ width, height }, { remove: () => this.remove(fn) });
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
}
|
|
33
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import PublicTimeline from '../timeline/public';
|
|
2
|
+
import { takeProp } from '../utils/internal';
|
|
3
|
+
import { pageOffset } from '../utils/utils';
|
|
4
|
+
import ScrollEvent from './ScrollEvent';
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
run animation when in view (start stop resume when different events happen)
|
|
@@ -23,8 +24,33 @@ scroll pin (once in trigger zone, elements keeps it position relative to start o
|
|
|
23
24
|
parallax
|
|
24
25
|
*/
|
|
25
26
|
|
|
27
|
+
type StartEndOffset = {
|
|
28
|
+
target: HTMLElement;
|
|
29
|
+
offset: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type Start = {
|
|
33
|
+
y: number;
|
|
34
|
+
view: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type End = {
|
|
38
|
+
y: number;
|
|
39
|
+
view: number;
|
|
40
|
+
};
|
|
26
41
|
|
|
27
42
|
export default class Scroll {
|
|
43
|
+
private _start: StartEndOffset;
|
|
44
|
+
private _end: StartEndOffset | null;
|
|
45
|
+
private _globalEvent: ScrollEvent;
|
|
46
|
+
|
|
47
|
+
start: Start;
|
|
48
|
+
end: End;
|
|
49
|
+
|
|
50
|
+
private timelines: PublicTimeline[];
|
|
51
|
+
private _rmEvent: () => void;
|
|
52
|
+
private _initialized: boolean;
|
|
53
|
+
|
|
28
54
|
constructor(props = {}) {
|
|
29
55
|
// { target, offset }
|
|
30
56
|
this._start = parseStart(takeProp(props, 'start', null));
|
|
@@ -36,14 +62,14 @@ export default class Scroll {
|
|
|
36
62
|
// px
|
|
37
63
|
y: 0,
|
|
38
64
|
// percentage
|
|
39
|
-
view: parseOffset(takeProp(props, 'startView', 'top'))
|
|
65
|
+
view: parseOffset(takeProp(props, 'startView', 'top')),
|
|
40
66
|
};
|
|
41
67
|
this.end = {
|
|
42
68
|
// px
|
|
43
69
|
y: 0,
|
|
44
70
|
// percentage
|
|
45
|
-
view: parseOffset(takeProp(props, 'endView', 'bottom'))
|
|
46
|
-
}
|
|
71
|
+
view: parseOffset(takeProp(props, 'endView', 'bottom')),
|
|
72
|
+
};
|
|
47
73
|
|
|
48
74
|
this.timelines = [];
|
|
49
75
|
|
|
@@ -51,14 +77,14 @@ export default class Scroll {
|
|
|
51
77
|
this._initialized = false;
|
|
52
78
|
}
|
|
53
79
|
|
|
54
|
-
addTimeline(timeline) {
|
|
80
|
+
addTimeline(timeline: PublicTimeline) {
|
|
55
81
|
this.timelines.push(timeline);
|
|
56
82
|
}
|
|
57
83
|
|
|
58
84
|
init() {
|
|
59
85
|
const startOffset = pageOffset(this._start.target);
|
|
60
|
-
this.start.y =
|
|
61
|
-
startOffset.height * this._start.offset;
|
|
86
|
+
this.start.y =
|
|
87
|
+
startOffset.top + startOffset.height * this._start.offset;
|
|
62
88
|
|
|
63
89
|
if (this._end) {
|
|
64
90
|
const offset = pageOffset(this._end.target);
|
|
@@ -68,7 +94,7 @@ export default class Scroll {
|
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
|
|
71
|
-
_onScroll({ y, height }) {
|
|
97
|
+
_onScroll({ y, height }: { y: number; height: number }) {
|
|
72
98
|
if (!this._initialized) {
|
|
73
99
|
this.init();
|
|
74
100
|
this._initialized = true;
|
|
@@ -86,11 +112,11 @@ export default class Scroll {
|
|
|
86
112
|
}
|
|
87
113
|
}
|
|
88
114
|
|
|
89
|
-
function parseStart(val) {
|
|
115
|
+
function parseStart(val: any): StartEndOffset {
|
|
90
116
|
// might be an object { target, offset }
|
|
91
117
|
if (!val) {
|
|
92
118
|
throw new Error(
|
|
93
|
-
'unknown start property use an html element or an object'
|
|
119
|
+
'unknown start property use an html element or an object',
|
|
94
120
|
);
|
|
95
121
|
}
|
|
96
122
|
|
|
@@ -98,12 +124,10 @@ function parseStart(val) {
|
|
|
98
124
|
let offset = 'top';
|
|
99
125
|
|
|
100
126
|
if (typeof val === 'object') {
|
|
101
|
-
if (val instanceof HTMLElement)
|
|
102
|
-
element = val;
|
|
127
|
+
if (val instanceof HTMLElement) element = val;
|
|
103
128
|
else if ('target' in val) {
|
|
104
129
|
element = val.target;
|
|
105
|
-
if (typeof val.offset !== 'undefined')
|
|
106
|
-
offset = val.offset;
|
|
130
|
+
if (typeof val.offset !== 'undefined') offset = val.offset;
|
|
107
131
|
} else {
|
|
108
132
|
throw new Error('start unknown ' + val);
|
|
109
133
|
}
|
|
@@ -113,25 +137,22 @@ function parseStart(val) {
|
|
|
113
137
|
|
|
114
138
|
return {
|
|
115
139
|
target: element,
|
|
116
|
-
offset: parseOffset(offset)
|
|
140
|
+
offset: parseOffset(offset),
|
|
117
141
|
};
|
|
118
142
|
}
|
|
119
143
|
|
|
120
|
-
function parseEnd(val) {
|
|
144
|
+
function parseEnd(val: any): StartEndOffset | null {
|
|
121
145
|
// might be an object { target, offset }
|
|
122
|
-
if (!val)
|
|
123
|
-
return null;
|
|
146
|
+
if (!val) return null;
|
|
124
147
|
|
|
125
148
|
let element = null;
|
|
126
149
|
let offset = 'top';
|
|
127
150
|
|
|
128
151
|
if (typeof val === 'object') {
|
|
129
|
-
if (val instanceof HTMLElement)
|
|
130
|
-
element = val;
|
|
152
|
+
if (val instanceof HTMLElement) element = val;
|
|
131
153
|
else if ('target' in val) {
|
|
132
154
|
element = val.target;
|
|
133
|
-
if (typeof val.offset !== 'undefined')
|
|
134
|
-
offset = val.offset;
|
|
155
|
+
if (typeof val.offset !== 'undefined') offset = val.offset;
|
|
135
156
|
} else {
|
|
136
157
|
throw new Error('start unknown ' + val);
|
|
137
158
|
}
|
|
@@ -141,29 +162,26 @@ function parseEnd(val) {
|
|
|
141
162
|
|
|
142
163
|
return {
|
|
143
164
|
target: element,
|
|
144
|
-
offset: parseOffset(offset)
|
|
165
|
+
offset: parseOffset(offset),
|
|
145
166
|
};
|
|
146
167
|
}
|
|
147
168
|
|
|
148
|
-
function parseOffset(val) {
|
|
169
|
+
function parseOffset(val: any): number {
|
|
149
170
|
if (typeof val === 'string') {
|
|
150
|
-
if (val === 'top')
|
|
151
|
-
return 0;
|
|
171
|
+
if (val === 'top') return 0;
|
|
152
172
|
|
|
153
|
-
if (val === 'center')
|
|
154
|
-
return .5;
|
|
173
|
+
if (val === 'center') return 0.5;
|
|
155
174
|
|
|
156
|
-
if (val === 'bottom')
|
|
157
|
-
return 1;
|
|
175
|
+
if (val === 'bottom') return 1;
|
|
158
176
|
|
|
159
177
|
throw new Error('unknown view value ' + val);
|
|
160
178
|
}
|
|
161
179
|
|
|
162
|
-
if (
|
|
180
|
+
if (typeof val !== 'number') {
|
|
163
181
|
throw new Error(
|
|
164
|
-
'view expecting to be a top/center/bottom or a percent value'
|
|
182
|
+
'view expecting to be a top/center/bottom or a percent value',
|
|
165
183
|
);
|
|
166
184
|
}
|
|
167
185
|
|
|
168
186
|
return val;
|
|
169
|
-
}
|
|
187
|
+
}
|