Skip to content

Commit b80831e

Browse files
committed
Tests for "tween", updated typings for easier extension with actions, also watch for recompile on index.d.ts changes
1 parent 0391900 commit b80831e

15 files changed

+286
-166
lines changed

Diff for: grunt/options/watch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
main: {
3-
files: ["src/**/*.ts"],
3+
files: ["index.d.ts", "src/**/*.ts"],
44
tasks: ["default"]
55
},
66
test: {

Diff for: index.d.ts

+187-68
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@ type VelocityEasingType = VelocityEasingFn
4040
| string
4141
| number[];
4242

43-
/**
44-
* Chaining Velocity calls from various sources.
45-
*/
46-
interface VelocityExtended<TNode extends Node = HTMLorSVGElement> {
47-
velocity: Velocity & {
48-
(action: "finish", queue?: string): VelocityResult;
49-
(action: "option", option: string): any;
50-
(action: "option", option: string, value: any): VelocityResult;
51-
(action: "pause", queue?: string): VelocityResult;
52-
(action: "resume", queue?: string): VelocityResult;
53-
(action: "stop", queue?: string): VelocityResult;
54-
(action: string, ...args: any[]): VelocityResult;
55-
(propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", complete?: () => void): VelocityResult;
56-
(propertyMap: string | VelocityProperties, complete?: () => void): VelocityResult;
57-
(propertyMap: string | VelocityProperties, easing?: VelocityEasingType, complete?: () => void): VelocityResult;
58-
(propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", easing?: VelocityEasingType, complete?: () => void): VelocityResult;
59-
(propertyMap: string | VelocityProperties, option?: VelocityOptions): VelocityResult;
60-
/**
61-
* TODO: Decide if this should be public
62-
* @private
63-
*/
64-
animations: AnimationCall[]
65-
}
66-
}
67-
6843
/**
6944
* The return type of any velocity call. If this is called via a "utility"
7045
* function (such a jQuery <code>$(elements).velocity(...)</code>) then it will
@@ -490,7 +465,7 @@ declare const enum AnimationFlags {
490465
/**
491466
* Set when an animation is manually stopped.
492467
*/
493-
STOPPED = 1<<4,
468+
STOPPED = 1 << 4,
494469
}
495470

496471
interface AnimationCall extends StrictVelocityOptions {
@@ -566,18 +541,40 @@ interface AnimationCall extends StrictVelocityOptions {
566541
percentComplete?: number;
567542
}
568543

544+
/**
545+
* VelocityChain is used to extend the chained Velocity calls with specific
546+
* actions and their arguments.
547+
*/
548+
interface VelocityChain {
549+
(action: string, ...args: any[]): any | VelocityResult;
550+
(propertyMap: string | VelocityProperties, complete?: () => void): VelocityResult;
551+
(propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", complete?: () => void): VelocityResult;
552+
(propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", easing?: VelocityEasingType, complete?: () => void): VelocityResult;
553+
(propertyMap: string | VelocityProperties, easing?: VelocityEasingType, complete?: () => void): VelocityResult;
554+
(propertyMap: string | VelocityProperties, option?: VelocityOptions): VelocityResult;
555+
}
556+
557+
/**
558+
* Direct Velocity access.
559+
*/
569560
interface Velocity {
570561
// TODO: Add all variations of the velocity argument formats allowed. Make them TYPE based as they're used in multiple places.
571-
(options?: VelocityObjectArgs | string): VelocityResult;
572-
(elements: VelocityElements, propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", complete?: () => void): VelocityResult;
573-
(elements: VelocityElements, propertyMap: string | VelocityProperties, complete?: () => void): VelocityResult;
574-
(elements: VelocityElements, propertyMap: string | VelocityProperties, easing?: string | number[], complete?: () => void): VelocityResult;
575-
(elements: VelocityElements, propertyMap: string | VelocityProperties, duration?: number | "fast" | "normal" | "slow", easing?: string | number[], complete?: () => void): VelocityResult;
576-
(elements: VelocityElements, propertyMap: string | VelocityProperties): VelocityResult;
577-
(elements: VelocityElements, propertyMap: string | VelocityProperties, options: VelocityOptions): VelocityResult;
578-
(elements: VelocityElements, propertyMap: string, option: any, value: any): VelocityResult;
579-
580-
defaults: VelocityOptions & {reset: () => void};
562+
(options: VelocityObjectArgs): VelocityResult;
563+
(action: string, ...args: any[]): VelocityResult;
564+
(elements: VelocityElements, action: string, ...args: any[]): VelocityResult;
565+
(elements: VelocityElements, propertyMap: VelocityProperties, complete?: () => void): VelocityResult;
566+
(elements: VelocityElements, propertyMap: VelocityProperties, duration?: number | "fast" | "normal" | "slow", complete?: () => void): VelocityResult;
567+
(elements: VelocityElements, propertyMap: VelocityProperties, duration?: number | "fast" | "normal" | "slow", easing?: string | number[], complete?: () => void): VelocityResult;
568+
(elements: VelocityElements, propertyMap: VelocityProperties, easing?: string | number[], complete?: () => void): VelocityResult;
569+
(elements: VelocityElements, propertyMap: VelocityProperties, options?: VelocityOptions): VelocityResult;
570+
571+
defaults: VelocityOptions & {
572+
/**
573+
* Provided in order to reset Velocity defaults back to their initial
574+
* state.
575+
*/
576+
reset: () => void
577+
};
581578

582579
queue(element: HTMLorSVGElement, animation: AnimationCall, queue?: string | boolean): void;
583580
dequeue(element: HTMLorSVGElement, queue?: string | boolean, skip?: boolean): AnimationCall;
@@ -587,34 +584,20 @@ interface Velocity {
587584
RunSequence(originalSequence): void;
588585
RegisterEffect(effectName: string, properties): Velocity;
589586

590-
/**
591-
* Expose a style shortcut - can't be used with chaining, but might be of
592-
* use to people.
593-
*/
594-
style(elements: VelocityResult, property: {[property: string]: string}): VelocityResult;
595-
style(elements: VelocityResult, property: string): string | string[];
596-
style(elements: VelocityResult, property: string, value: string): VelocityResult;
597-
598587
/**
599588
* Available to be able to check what version you're running against.
600589
*/
601-
version: {
602-
major: number;
603-
minor: number;
604-
patch: number;
590+
readonly version: {
591+
readonly major: number;
592+
readonly minor: number;
593+
readonly patch: number;
605594
}
606595

607596
CSS: {
608597
getPropertyValue(element: HTMLorSVGElement, property: string, rootPropertyValue?: string, forceStyleLookup?: boolean): string | number;
609598
getUnit(str: string, start?: number): string;
610599
fixColors(str: string): string;
611600
Normalizations: {[name: string]: VelocityNormalizationsFn};
612-
// Hooks: {
613-
// getRoot(property: string): string;
614-
// cleanRootPropertyValue(rootProperty: string, rootPropertyValue: string): string;
615-
// extractValue(fullHookName: string, rootPropertyValue: string): string;
616-
// injectValue(fullHookName: string, hookValue: string, rootPropertyValue: string): string;
617-
// };
618601
Names: {
619602
camelCase(property: string): string;
620603
SVGAttribute(property: string): boolean;
@@ -629,82 +612,219 @@ interface Velocity {
629612
removeClass(element: HTMLorSVGElement, className: string): void;
630613
};
631614
};
632-
State: {
615+
/**
616+
* Current internal state of Velocity.
617+
*/
618+
readonly State: {
633619
/**
634620
* Detect if this is a NodeJS or web browser
635621
*/
636-
isClient: boolean;
622+
readonly isClient: boolean;
637623
/**
638624
* Detect mobile devices to determine if mobileHA should be turned
639625
* on.
640626
*/
641-
isMobile: boolean;
627+
readonly isMobile: boolean;
642628
/**
643629
* The mobileHA option's behavior changes on older Android devices
644630
* (Gingerbread, versions 2.3.3-2.3.7).
645631
*/
646-
isAndroid: boolean;
632+
readonly isAndroid: boolean;
647633
/**
648634
* The mobileHA option's behavior changes on older Android devices
649635
* (Gingerbread, versions 2.3.3-2.3.7).
650636
*/
651-
isGingerbread: boolean;
637+
readonly isGingerbread: boolean;
652638
/**
653639
* Chrome browser
654640
*/
655-
isChrome: boolean;
641+
readonly isChrome: boolean;
656642
/**
657643
* Firefox browser
658644
*/
659-
isFirefox: boolean;
645+
readonly isFirefox: boolean;
660646
/**
661647
* Create a cached element for re-use when checking for CSS property
662648
* prefixes.
663649
*/
664-
prefixElement: boolean;
650+
readonly prefixElement: boolean;
665651
/**
666652
* Cache every prefix match to avoid repeating lookups.
667653
*/
668-
prefixMatches: {[property: string]: string};
654+
readonly prefixMatches: {[property: string]: string};
669655
/**
670656
* Retrieve the appropriate scroll anchor and property name for the
671657
* browser: https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY
658+
*
659+
* @deprecated
672660
*/
673661
windowScrollAnchor: boolean;
674662
/**
675663
* Cache the anchor used for animating window scrolling.
664+
*
665+
* @deprecated
676666
*/
677667
scrollAnchor: Element;
678668
/**
679669
* Cache the browser-specific property names associated with the
670+
*
671+
* @deprecated
680672
* scroll anchor.
681673
*/
682674
scrollPropertyLeft: string;
683675
/**
684676
* Cache the browser-specific property names associated with the
677+
*
678+
* @deprecated
685679
* scroll anchor.
686680
*/
687681
scrollPropertyTop: string;
688682
/**
689683
* Keep track of whether our RAF tick is running.
690684
*/
691-
isTicking: boolean;
685+
readonly isTicking: boolean;
692686
/**
693687
* Container for every in-progress call to Velocity.
694688
*/
695-
first: AnimationCall;
689+
readonly first: AnimationCall;
696690
/**
697691
* Container for every in-progress call to Velocity.
698692
*/
699-
last: AnimationCall;
693+
readonly last: AnimationCall;
700694
/**
701695
* First new animation - to shortcut starting them all up and push
702696
* any css reads to the start of the tick
703697
*/
704-
firstNew: AnimationCall;
698+
readonly firstNew: AnimationCall;
705699
};
706700
}
707701

702+
/**
703+
* Chaining Velocity calls from various sources.
704+
*/
705+
interface VelocityExtended<TNode extends Node = HTMLorSVGElement> {
706+
velocity: Velocity & VelocityChain & {
707+
/**
708+
* TODO: Decide if this should be public
709+
* @private
710+
*/
711+
animations: AnimationCall[]
712+
}
713+
}
714+
715+
////////////////////
716+
// Action: Finish //
717+
////////////////////
718+
interface Velocity {
719+
(action: "finish", queue?: string): VelocityResult;
720+
(elements: VelocityElements, action: "finish", queue?: string): VelocityResult;
721+
}
722+
723+
interface VelocityChain {
724+
(action: "finish", queue?: string): VelocityResult;
725+
}
726+
727+
////////////////////
728+
// Action: Option //
729+
////////////////////
730+
interface Velocity {
731+
(action: "option", option: string): any;
732+
(action: "option", option: string, value: any): VelocityResult;
733+
(elements: VelocityElements, action: "option", option: string): any;
734+
(elements: VelocityElements, action: "option", option: string, value: any): VelocityResult;
735+
}
736+
737+
interface VelocityChain {
738+
(action: "option", option: string): any;
739+
(action: "option", option: string, value: any): VelocityResult;
740+
}
741+
742+
///////////////////
743+
// Action: Pause //
744+
///////////////////
745+
interface Velocity {
746+
(action: "pause", queue?: string): VelocityResult;
747+
(elements: VelocityElements, action: "pause", queue?: string): VelocityResult;
748+
}
749+
750+
interface VelocityChain {
751+
(action: "pause", queue?: string): VelocityResult;
752+
}
753+
754+
////////////////////
755+
// Action: Resume //
756+
////////////////////
757+
interface Velocity {
758+
(action: "resume", queue?: string): VelocityResult;
759+
(elements: VelocityElements, action: "resume", queue?: string): VelocityResult;
760+
}
761+
762+
interface VelocityChain {
763+
(action: "resume", queue?: string): VelocityResult;
764+
}
765+
766+
////////////////////
767+
// Action: Resume //
768+
////////////////////
769+
interface Velocity {
770+
(action: "resume", queue?: string): VelocityResult;
771+
(elements: VelocityElements, action: "resume", queue?: string): VelocityResult;
772+
}
773+
774+
interface VelocityChain {
775+
(action: "resume", queue?: string): VelocityResult;
776+
}
777+
778+
//////////////////
779+
// Action: Stop //
780+
//////////////////
781+
interface Velocity {
782+
(action: "stop", queue?: string): VelocityResult;
783+
(elements: VelocityElements, action: "stop", queue?: string): VelocityResult;
784+
}
785+
786+
interface VelocityChain {
787+
(action: "stop", queue?: string): VelocityResult;
788+
}
789+
790+
///////////////////
791+
// Action: Style //
792+
///////////////////
793+
interface Velocity {
794+
(action: "style", property: {[property: string]: string}): VelocityResult;
795+
(action: "style", property: string): string | string[];
796+
(action: "style", property: string, value: string): VelocityResult;
797+
(element: HTMLorSVGElement, action: "style", property: string): string;
798+
(elements: VelocityElements, action: "style", property: {[property: string]: string}): VelocityResult;
799+
(elements: VelocityElements, action: "style", property: string): string | string[];
800+
(elements: VelocityElements, action: "style", property: string, value: string): VelocityResult;
801+
802+
style(elements: VelocityResult, property: {[property: string]: string}): VelocityResult;
803+
style(elements: VelocityResult, property: string): string | string[];
804+
style(elements: VelocityResult, property: string, value: string): VelocityResult;
805+
}
806+
807+
interface VelocityChain {
808+
(action: "style", property: {[property: string]: string}): VelocityResult;
809+
(action: "style", property: string): string | string[];
810+
(action: "style", property: string, value: string): VelocityResult;
811+
}
812+
813+
///////////////////
814+
// Action: Tween //
815+
///////////////////
816+
interface Velocity {
817+
(action: "tween", percentComplete: number, property: string, value: VelocityPropertyValue, easing?: VelocityEasingType): string;
818+
(action: "tween", percentComplete: number, propertyMap: VelocityProperties, easing?: VelocityEasingType): {[property in keyof CSSStyleDeclaration]?: string};
819+
(elements: VelocityElements, action: "tween", percentComplete: number, property: string, value: VelocityPropertyValue, easing?: VelocityEasingType): string;
820+
(elements: VelocityElements, action: "tween", percentComplete: number, propertyMap: VelocityProperties, easing?: VelocityEasingType): {[property in keyof CSSStyleDeclaration]?: string};
821+
}
822+
823+
interface VelocityChain {
824+
(action: "tween", percentComplete: number, property: string, value: VelocityPropertyValue, easing?: VelocityEasingType): string;
825+
(action: "tween", percentComplete: number, propertyMap: VelocityProperties, easing?: VelocityEasingType): {[property in keyof CSSStyleDeclaration]?: string};
826+
}
827+
708828
/**
709829
* Extend the return value from <code>document.querySelectorAll()</code>.
710830
*/
@@ -715,7 +835,6 @@ interface NodeListOf<TNode extends Node> extends VelocityExtended<TNode> {}
715835
*/
716836
interface Element extends VelocityExtended<Element> {}
717837

718-
719838
/**
720839
* Extend <code>Element</code> directly.
721840
*/

Diff for: src/Velocity/_all.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
///<reference path="data.ts" />
77
///<reference path="debug.ts" />
88
///<reference path="defaults.ts" />
9-
///<reference path="hook.ts" />
109
///<reference path="mock.ts" />
1110
///<reference path="queue.ts" />
1211
///<reference path="redirects.ts" />

0 commit comments

Comments
 (0)