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
package/src/responsive/event.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export default class ResponsiveEvent {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._listeners = new Set;
|
|
4
|
-
|
|
5
|
-
window.addEventListener('resize', e => this._onResize(e));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static global() {
|
|
9
|
-
// allow to define a test ticker
|
|
10
|
-
if (typeof globalThis !== 'undefined' && globalThis.chnobliResponsive)
|
|
11
|
-
return globalThis.chnobliResponsive;
|
|
12
|
-
|
|
13
|
-
if (typeof window === 'undefined')
|
|
14
|
-
return null;
|
|
15
|
-
|
|
16
|
-
if (typeof window.chnobliResponsive === 'undefined')
|
|
17
|
-
window.chnobliResponsive = new ResponsiveEvent;
|
|
18
|
-
return window.chnobliResponsive;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// fn({ width, height }, { remove() })
|
|
22
|
-
add(fn) {
|
|
23
|
-
this._listeners.add(fn);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
remove: () => {
|
|
27
|
-
this.remove(fn);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
remove(fn) {
|
|
33
|
-
this._listeners.delete(fn);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
_onResize(_e) {
|
|
37
|
-
for (const fn of this._listeners) {
|
|
38
|
-
fn({
|
|
39
|
-
width: window.innerWidth,
|
|
40
|
-
height: window.innerHeight
|
|
41
|
-
}, {
|
|
42
|
-
remove: () => this.remove(fn)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/scroll/event.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export default class ScrollEvent {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._listeners = new Set;
|
|
4
|
-
|
|
5
|
-
window.addEventListener('scroll', e => this._onScroll(e));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static global() {
|
|
9
|
-
if (typeof window === 'undefined')
|
|
10
|
-
return null;
|
|
11
|
-
|
|
12
|
-
if (typeof window.chnobliScroll === 'undefined')
|
|
13
|
-
window.chnobliScroll = new ScrollEvent;
|
|
14
|
-
return window.chnobliScroll;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
add(fn) {
|
|
18
|
-
this._listeners.add(fn);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
remove: () => {
|
|
22
|
-
this.remove(fn);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
remove(fn) {
|
|
28
|
-
this._listeners.delete(fn);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_onScroll(_e) {
|
|
32
|
-
for (const fn of this._listeners) {
|
|
33
|
-
fn({
|
|
34
|
-
y: window.scrollY,
|
|
35
|
-
height: window.innerHeight
|
|
36
|
-
}, {
|
|
37
|
-
remove: () => this.remove(fn)
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
package/src/scroll/public.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Scroll from './scroll.js';
|
|
2
|
-
|
|
3
|
-
export default class PublicScroll {
|
|
4
|
-
/*
|
|
5
|
-
{
|
|
6
|
-
start: el | px
|
|
7
|
-
startView: 'top'
|
|
8
|
-
}
|
|
9
|
-
*/
|
|
10
|
-
constructor(props = {}) {
|
|
11
|
-
this._inner = new Scroll(props);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
add(timeline) {
|
|
15
|
-
this._inner.addTimeline(timeline);
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/stagger/stagger.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Staggering allows to have a different value for every target
|
|
3
|
-
* allowing to easely offset each target by a few pixels
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
function isStagger(value) {
|
|
7
|
-
return typeof value === 'object' &&
|
|
8
|
-
value !== null &&
|
|
9
|
-
typeof value.__isStagger__ === 'function';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function callStagger(value, i, l) {
|
|
13
|
-
if (isStagger(value))
|
|
14
|
-
return value.call(i, l);
|
|
15
|
-
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function staggerMap(value, fn) {
|
|
20
|
-
if (isStagger(value))
|
|
21
|
-
return new Stagger((...args) => fn(value.call(...args)));
|
|
22
|
-
|
|
23
|
-
return fn(value);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default class Stagger {
|
|
27
|
-
constructor(value) {
|
|
28
|
-
if (typeof value === 'function') {
|
|
29
|
-
this.fn = value;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// if (value === )
|
|
34
|
-
throw new Error('unknown stagger value ' + value);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
call(...args) {
|
|
38
|
-
return this.fn(...args);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
__isStagger__() {}
|
|
42
|
-
}
|
package/src/target/domtarget.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import BaseTarget from './basetarget.js';
|
|
2
|
-
import Value from '../values/value.js';
|
|
3
|
-
import StyleValue from '../values/stylevalue.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default class DomTarget extends BaseTarget {
|
|
7
|
-
/**
|
|
8
|
-
* target a dom node or svg
|
|
9
|
-
*
|
|
10
|
-
* extFns: {getComputedStyle, getRootElement}
|
|
11
|
-
*/
|
|
12
|
-
constructor(target, extFns) {
|
|
13
|
-
super(target);
|
|
14
|
-
|
|
15
|
-
this._extFns = extFns;
|
|
16
|
-
|
|
17
|
-
// for the moment
|
|
18
|
-
|
|
19
|
-
this.transformValues = new Map;
|
|
20
|
-
this.styleValues = new Map;
|
|
21
|
-
this.values = new Map;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type() {
|
|
25
|
-
return 'dom';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getValue(name) {
|
|
29
|
-
return this.values.get(name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
setValue(name, value) {
|
|
33
|
-
this.values.set(name, value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
removeValue(name) {
|
|
37
|
-
this.values.delete(name);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getTransformValue(name) {
|
|
41
|
-
const [fn, idx] = TRANSFORM_PROPS[name] ?? [];
|
|
42
|
-
if (!fn)
|
|
43
|
-
return null;
|
|
44
|
-
|
|
45
|
-
const r = this.transformValues.get(fn);
|
|
46
|
-
return r?.[idx ?? 0] ?? null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setTransformValue(name, value) {
|
|
50
|
-
const [fn, idx] = TRANSFORM_PROPS[name] ?? [];
|
|
51
|
-
if (!fn)
|
|
52
|
-
throw new Error('unknown transform ' + name);
|
|
53
|
-
|
|
54
|
-
let vals = this.transformValues.get(fn);
|
|
55
|
-
if (!vals)
|
|
56
|
-
vals = Array(TRANSFORM_FUNCTIONS[fn].length).fill(null);
|
|
57
|
-
|
|
58
|
-
if (idx === null)
|
|
59
|
-
vals = vals.map(() => value.clone());
|
|
60
|
-
else
|
|
61
|
-
vals[idx] = value;
|
|
62
|
-
|
|
63
|
-
this.transformValues.set(fn, vals);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
removeTransformValue(name) {
|
|
67
|
-
const [fn, idx] = TRANSFORM_PROPS[name] ?? [];
|
|
68
|
-
if (!fn)
|
|
69
|
-
return;
|
|
70
|
-
|
|
71
|
-
if (idx === null) {
|
|
72
|
-
this.transformValues.delete(fn);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let vals = this.transformValues.get(fn);
|
|
77
|
-
if (!vals)
|
|
78
|
-
return;
|
|
79
|
-
|
|
80
|
-
vals[idx] = null;
|
|
81
|
-
|
|
82
|
-
if (vals.every(v => v === null))
|
|
83
|
-
this.transformValues.delete(fn);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getStyleValue(name) {
|
|
87
|
-
const v = this.styleValues.get(name);
|
|
88
|
-
|
|
89
|
-
if (typeof v === 'undefined' || v === null) {
|
|
90
|
-
// let's try to get it from the dom
|
|
91
|
-
const style = this._extFns.getComputedStyle(this.target);
|
|
92
|
-
const styleV = style.getPropertyValue(name);
|
|
93
|
-
|
|
94
|
-
if (typeof styleV === 'undefined' || styleV === null)
|
|
95
|
-
return styleV;
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const value = StyleValue.parse(styleV);
|
|
99
|
-
this.styleValues.set(name, value);
|
|
100
|
-
|
|
101
|
-
return value;
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.log('could not parse value', styleV);
|
|
104
|
-
return v;
|
|
105
|
-
}
|
|
106
|
-
} else
|
|
107
|
-
return v;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setStyleValue(name, value) {
|
|
111
|
-
this.styleValues.set(name, value);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
removeStyleValue(name) {
|
|
115
|
-
this.styleValues.set(name, undefined);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
hasClass(name) {
|
|
119
|
-
return this.target.classList.contains(name);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
addClass(name) {
|
|
123
|
-
return this.target.classList.add(name);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
removeClass(name) {
|
|
127
|
-
return this.target.classList.remove(name);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_getRem() {
|
|
131
|
-
const rootEl = this._extFns.getRootElement();
|
|
132
|
-
const style = this._extFns.getComputedStyle(rootEl);
|
|
133
|
-
const fontSize = Value.parse(style.fontSize, 'px');
|
|
134
|
-
if (fontSize.unit !== 'px')
|
|
135
|
-
throw new Error('rem could not be determined');
|
|
136
|
-
|
|
137
|
-
return fontSize.num;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_convertToPx(name, value) {
|
|
141
|
-
if (value.num === 0)
|
|
142
|
-
return new Value(0, 'px');
|
|
143
|
-
|
|
144
|
-
switch (value.unit) {
|
|
145
|
-
case 'px':
|
|
146
|
-
return value;
|
|
147
|
-
case 'rem':
|
|
148
|
-
return new Value(value.num * this._getRem(), 'px');
|
|
149
|
-
default:
|
|
150
|
-
throw new Error(
|
|
151
|
-
`cannot convert ${name} from ${value.unit} to px`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// value needs to be a unit with pixels
|
|
157
|
-
_convertFromPx(name, value, unit) {
|
|
158
|
-
if (value.num === 0)
|
|
159
|
-
return new Value(0, unit);
|
|
160
|
-
|
|
161
|
-
let v;
|
|
162
|
-
switch (unit) {
|
|
163
|
-
case 'px':
|
|
164
|
-
return value;
|
|
165
|
-
|
|
166
|
-
case 'rem':
|
|
167
|
-
return new Value(value.num / this._getRem(), 'rem');
|
|
168
|
-
|
|
169
|
-
case '%':
|
|
170
|
-
v = this.getStyleValue(name).intoValue();
|
|
171
|
-
if (v.unit !== 'px')
|
|
172
|
-
throw new Error('cannot get style value of ' + name);
|
|
173
|
-
|
|
174
|
-
return new Value((value.num / v.num) * 100, '%');
|
|
175
|
-
|
|
176
|
-
default:
|
|
177
|
-
throw new Error(
|
|
178
|
-
`cannot convert ${name} from px to ${unit}`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
unifyValues(name, a, b) {
|
|
184
|
-
if (a.unit === b.unit)
|
|
185
|
-
return [a, b];
|
|
186
|
-
|
|
187
|
-
if (!a.unit && b.unit)
|
|
188
|
-
a.unit = b.unit;
|
|
189
|
-
|
|
190
|
-
if (!b.unit && a.unit)
|
|
191
|
-
b.unit = a.unit;
|
|
192
|
-
|
|
193
|
-
const aPx = this._convertToPx(name, a);
|
|
194
|
-
const aBUnit = this._convertFromPx(name, aPx, b.unit);
|
|
195
|
-
|
|
196
|
-
return [aBUnit, b];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
apply() {
|
|
200
|
-
this.target.style.transform = Array.from(this.transformValues.entries())
|
|
201
|
-
.map(([k, vals]) => {
|
|
202
|
-
// since we allow null in default Values we now need to make
|
|
203
|
-
// sure either a value or a default value are set for the
|
|
204
|
-
// transform function
|
|
205
|
-
|
|
206
|
-
const defVals = TRANSFORM_FUNCTIONS[k];
|
|
207
|
-
if (vals.length !== defVals.length)
|
|
208
|
-
throw new Error('transform values don\'t match');
|
|
209
|
-
|
|
210
|
-
const nArray = Array(vals.length);
|
|
211
|
-
|
|
212
|
-
for (let i = 0; i < vals.length; i++) {
|
|
213
|
-
let val = vals[i];
|
|
214
|
-
|
|
215
|
-
if (val === null)
|
|
216
|
-
val = new Value(defVals[i][0]);
|
|
217
|
-
|
|
218
|
-
nArray[i] = val.withDefaultUnit(defVals[i][1]);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return `${k}(${nArray.join(',')})`;
|
|
222
|
-
})
|
|
223
|
-
.join(' ');
|
|
224
|
-
|
|
225
|
-
// style
|
|
226
|
-
for (const [k, v] of this.styleValues.entries()) {
|
|
227
|
-
if (v === undefined) {
|
|
228
|
-
this.target.style.removeProperty(k);
|
|
229
|
-
// is this a problem?
|
|
230
|
-
this.styleValues.delete(k);
|
|
231
|
-
} else {
|
|
232
|
-
this.target.style.setProperty(k, v.toString());
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// values
|
|
237
|
-
for (const [k, _v] of this.values.entries()) {
|
|
238
|
-
console.log('what todo with this ' + k);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const TRANSFORM_PROPS = {
|
|
245
|
-
'x': ['translate3d', 0],
|
|
246
|
-
'y': ['translate3d', 1],
|
|
247
|
-
'z': ['translate3d', 2],
|
|
248
|
-
'scale': ['scale3d', null],
|
|
249
|
-
'scaleX': ['scale3d', 0],
|
|
250
|
-
'scaleY': ['scale3d', 1],
|
|
251
|
-
'scaleZ': ['scale3d', 2],
|
|
252
|
-
'rotate': ['rotate3d', null],
|
|
253
|
-
'rotateX': ['rotate3d', 0],
|
|
254
|
-
'rotateY': ['rotate3d', 1],
|
|
255
|
-
'rotateZ': ['rotate3d', 2],
|
|
256
|
-
'skew': ['skew', 0],
|
|
257
|
-
'skewX': ['skew', 0],
|
|
258
|
-
'skewY': ['skew', 1]
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const TRANSFORM_FUNCTIONS = {
|
|
262
|
-
'translate3d': [[0, 'px'], [0, 'px'], [0, 'px']],
|
|
263
|
-
'scale3d': [[1, null], [1, null], [1, null]],
|
|
264
|
-
'rotate3d': [[0, 'deg'], [0, 'deg'], [0, 'deg']],
|
|
265
|
-
'skew': [[0, 'deg'], [0, 'deg']]
|
|
266
|
-
};
|
package/src/target/target.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import DomTarget from './domtarget.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function newTarget(target) {
|
|
5
|
-
if (typeof window === 'undefined') {
|
|
6
|
-
if (typeof target.__simulatedDom__ === 'function') {
|
|
7
|
-
return new DomTarget(target, {
|
|
8
|
-
getComputedStyle: target.__getComputedStyleFn__(),
|
|
9
|
-
getRootElement: target.__getRootElementFn__()
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
} else {
|
|
13
|
-
if (target instanceof HTMLElement || target instanceof SVGElement) {
|
|
14
|
-
return new DomTarget(target, {
|
|
15
|
-
getComputedStyle: e => window.getComputedStyle(e),
|
|
16
|
-
getRootElement: () => document.documentElement
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
throw new Error('unknown target');
|
|
22
|
-
}
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import TestTicker from '../timing/testticker.js';
|
|
3
|
-
import { animate, timeline } from '../chnobli.js';
|
|
4
|
-
import { el } from '../target/testdomnode.js';
|
|
5
|
-
|
|
6
|
-
describe('timeline', () => {
|
|
7
|
-
it('empty timeline', () => {
|
|
8
|
-
const ticker = new TestTicker;
|
|
9
|
-
|
|
10
|
-
const tl = timeline();
|
|
11
|
-
tl.play();
|
|
12
|
-
const finished = ticker.run();
|
|
13
|
-
expect(finished).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('single timeline', () => {
|
|
17
|
-
const ticker = new TestTicker;
|
|
18
|
-
|
|
19
|
-
const tl = timeline();
|
|
20
|
-
const target = el();
|
|
21
|
-
tl.add(target, {
|
|
22
|
-
x: 10,
|
|
23
|
-
duration: 10
|
|
24
|
-
});
|
|
25
|
-
tl.play();
|
|
26
|
-
|
|
27
|
-
ticker.run(0);
|
|
28
|
-
expect(target.style.transform)
|
|
29
|
-
.toBe('translate3d(0.000px,0.000px,0.000px)');
|
|
30
|
-
|
|
31
|
-
ticker.run();
|
|
32
|
-
expect(target.style.transform)
|
|
33
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
34
|
-
|
|
35
|
-
tl.reverse();
|
|
36
|
-
tl.play();
|
|
37
|
-
ticker.run();
|
|
38
|
-
expect(target.style.transform).toBe('');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('timeline set', () => {
|
|
42
|
-
const ticker = new TestTicker;
|
|
43
|
-
|
|
44
|
-
const target = el();
|
|
45
|
-
const tl = timeline()
|
|
46
|
-
.set(target, {
|
|
47
|
-
x: 10
|
|
48
|
-
});
|
|
49
|
-
tl.play();
|
|
50
|
-
|
|
51
|
-
ticker.run(0);
|
|
52
|
-
expect(target.style.transform)
|
|
53
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
54
|
-
|
|
55
|
-
ticker.run();
|
|
56
|
-
expect(target.style.transform)
|
|
57
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
58
|
-
|
|
59
|
-
tl.reverse();
|
|
60
|
-
tl.play();
|
|
61
|
-
ticker.run();
|
|
62
|
-
expect(target.style.transform)
|
|
63
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('offsetTimeline timeline', () => {
|
|
67
|
-
const ticker = new TestTicker;
|
|
68
|
-
|
|
69
|
-
const tl = timeline();
|
|
70
|
-
const target = el();
|
|
71
|
-
tl.add(target, {
|
|
72
|
-
x: 10,
|
|
73
|
-
duration: 10
|
|
74
|
-
});
|
|
75
|
-
tl.add(target, {
|
|
76
|
-
x: 20,
|
|
77
|
-
duration: 10
|
|
78
|
-
})
|
|
79
|
-
tl.play();
|
|
80
|
-
|
|
81
|
-
ticker.run(10);
|
|
82
|
-
expect(target.style.transform)
|
|
83
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
84
|
-
ticker.run(1);
|
|
85
|
-
expect(target.style.transform)
|
|
86
|
-
.toBe('translate3d(11.000px,0.000px,0.000px)');
|
|
87
|
-
|
|
88
|
-
ticker.run();
|
|
89
|
-
expect(target.style.transform)
|
|
90
|
-
.toBe('translate3d(20.000px,0.000px,0.000px)');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('timeline seeking', () => {
|
|
94
|
-
const ticker = new TestTicker;
|
|
95
|
-
|
|
96
|
-
const tl = timeline();
|
|
97
|
-
const target = el();
|
|
98
|
-
tl.add(target, {
|
|
99
|
-
x: 10,
|
|
100
|
-
duration: 10
|
|
101
|
-
});
|
|
102
|
-
tl.add(target, {
|
|
103
|
-
x: 20,
|
|
104
|
-
duration: 10
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
tl.seekMs(10);
|
|
108
|
-
ticker.run();
|
|
109
|
-
expect(target.style.transform)
|
|
110
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
111
|
-
|
|
112
|
-
tl.seekMs(11);
|
|
113
|
-
ticker.run();
|
|
114
|
-
expect(target.style.transform)
|
|
115
|
-
.toBe('translate3d(11.000px,0.000px,0.000px)');
|
|
116
|
-
|
|
117
|
-
tl.seekMs(20);
|
|
118
|
-
ticker.run();
|
|
119
|
-
expect(target.style.transform)
|
|
120
|
-
.toBe('translate3d(20.000px,0.000px,0.000px)');
|
|
121
|
-
|
|
122
|
-
tl.seekMs(8);
|
|
123
|
-
ticker.run();
|
|
124
|
-
expect(target.style.transform)
|
|
125
|
-
.toBe('translate3d(8.000px,0.000px,0.000px)');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('seeking after', () => {
|
|
129
|
-
const ticker = new TestTicker;
|
|
130
|
-
|
|
131
|
-
const target = el();
|
|
132
|
-
const ani = animate(target, {
|
|
133
|
-
autoplay: false,
|
|
134
|
-
duration: 10,
|
|
135
|
-
x: 10
|
|
136
|
-
});
|
|
137
|
-
ani.seek(2);
|
|
138
|
-
|
|
139
|
-
ticker.run();
|
|
140
|
-
expect(target.style.transform)
|
|
141
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('timeline controls', () => {
|
|
145
|
-
const ticker = new TestTicker;
|
|
146
|
-
|
|
147
|
-
const tl = timeline();
|
|
148
|
-
const target = el();
|
|
149
|
-
tl.add(target, {
|
|
150
|
-
x: 10,
|
|
151
|
-
duration: 10
|
|
152
|
-
});
|
|
153
|
-
tl.add(target, {
|
|
154
|
-
x: 20,
|
|
155
|
-
duration: 10
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
tl.seekMs(10);
|
|
159
|
-
ticker.run();
|
|
160
|
-
expect(target.style.transform)
|
|
161
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
162
|
-
|
|
163
|
-
tl.play();
|
|
164
|
-
ticker.run();
|
|
165
|
-
expect(target.style.transform)
|
|
166
|
-
.toBe('translate3d(20.000px,0.000px,0.000px)');
|
|
167
|
-
|
|
168
|
-
tl.reset();
|
|
169
|
-
tl.play();
|
|
170
|
-
ticker.run(10);
|
|
171
|
-
expect(target.style.transform)
|
|
172
|
-
.toBe('translate3d(10.000px,0.000px,0.000px)');
|
|
173
|
-
|
|
174
|
-
tl.reverse();
|
|
175
|
-
ticker.run(5);
|
|
176
|
-
expect(target.style.transform)
|
|
177
|
-
.toBe('translate3d(5.000px,0.000px,0.000px)');
|
|
178
|
-
|
|
179
|
-
tl.reverse();
|
|
180
|
-
ticker.run();
|
|
181
|
-
expect(target.style.transform)
|
|
182
|
-
.toBe('translate3d(20.000px,0.000px,0.000px)');
|
|
183
|
-
|
|
184
|
-
tl.reverse();
|
|
185
|
-
tl.play();
|
|
186
|
-
ticker.run();
|
|
187
|
-
expect(target.style.transform).toBe('');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('timeline events', () => {
|
|
191
|
-
const ticker = new TestTicker;
|
|
192
|
-
|
|
193
|
-
const target = el();
|
|
194
|
-
const tl = timeline()
|
|
195
|
-
.add(target, {
|
|
196
|
-
x: 50,
|
|
197
|
-
duration: 10
|
|
198
|
-
})
|
|
199
|
-
.add(target, {
|
|
200
|
-
y: 50,
|
|
201
|
-
duration: 10
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
let endCounter = 0;
|
|
205
|
-
tl.on('end', () => endCounter += 1);
|
|
206
|
-
|
|
207
|
-
tl.play();
|
|
208
|
-
ticker.run(5);
|
|
209
|
-
expect(endCounter).toBe(0);
|
|
210
|
-
|
|
211
|
-
ticker.run();
|
|
212
|
-
expect(endCounter).toBe(1);
|
|
213
|
-
|
|
214
|
-
tl.play();
|
|
215
|
-
ticker.run();
|
|
216
|
-
// not sure this is the behaviour we wan't
|
|
217
|
-
expect(endCounter).toBe(2);
|
|
218
|
-
|
|
219
|
-
tl.reverse();
|
|
220
|
-
ticker.run();
|
|
221
|
-
expect(endCounter).toBe(2);
|
|
222
|
-
expect(target.style.transform)
|
|
223
|
-
.toBe('translate3d(50.000px,50.000px,0.000px)');
|
|
224
|
-
|
|
225
|
-
tl.play();
|
|
226
|
-
ticker.run();
|
|
227
|
-
expect(endCounter).toBe(3);
|
|
228
|
-
expect(target.style.transform).toBe('');
|
|
229
|
-
|
|
230
|
-
tl.play();
|
|
231
|
-
ticker.run();
|
|
232
|
-
expect(endCounter).toBe(4);
|
|
233
|
-
});
|
|
234
|
-
});
|