@@ -74,6 +74,18 @@ aside: false
74
74
jsCssAnimations .init .collapse (collapseOpts)
75
75
}
76
76
77
+ const validateAnimationFormField = {
78
+ timePropertyValidation : val => val .match (/ ^ (\d + | \d + \. \d + )(ms| s)? $ / ),
79
+ blur : val => val .match (/ ^ (\d + | \d + \. \d + )(px| rem| em)$ / ),
80
+ easing : val => {
81
+ const easingRegEx = / ^ (ease(-in| -out| -in-out)? | linear| cubic-bezier\( (0| 1| 0.\d + ), -? [\d \. ] + , (0| 1| 0.\d + ), -? [\d \. ] + \) | step\( (100| [0-9 ][0-9 ] | [0-9 ] ),\s ? (jump-start| jump-end| jump-none| jump-both| start| end)\) | step\( step-(start| end)\) )$ / ;
82
+ return val && val .match (easingRegEx)
83
+ },
84
+ duration : val => validateAnimationFormField .timePropertyValidation (val),
85
+ delay : val => validateAnimationFormField .timePropertyValidation (val),
86
+ staggerDelay : val => validateAnimationFormField .timePropertyValidation (val),
87
+ }
88
+
77
89
function resetAnimation (animName , {opts}) {
78
90
const btnList = examples[animName].btnList ;
79
91
btnList .forEach (btn => {
@@ -88,22 +100,20 @@ aside: false
88
100
blur: ' 0.5px'
89
101
}
90
102
91
- const easingRegEx = / ^ (ease(-in| -out| -in-out)? | linear| cubic-bezier\( (0| 1| 0.\d + ), -? [\d \. ] + , (0| 1| 0.\d + ), -? [\d \. ] + \) | step\( (100| [0-9 ][0-9 ] | [0-9 ] ),\s ? (jump-start| jump-end| jump-none| jump-both| start| end)\) | step\( step-(start| end)\) )$ / ;
92
-
93
103
if (opts .maintainSpace ) opts .dimensionsTransition = false ;
94
- if (! opts .blur . match ( / ^ ( \d + | \d + \. \d + )(px | rem | em) $ / )) opts .blur = defaultValue .blur ;
95
- if (! opts .easing || ! opts .easing . match (easingRegEx ))
104
+ if (! validateAnimationFormField .blur ( opts . blur )) opts .blur = defaultValue .blur ;
105
+ if (! validateAnimationFormField .easing ( opts .easing ))
96
106
opts .easing = defaultValue .timingFunction ;
97
107
[' duration' , ' delay' , ' staggerDelay' ].forEach (prop => {
98
- if (opts[prop].match (/ ^ \d + $ / )) opts[prop] = ` ${ opts[prop]} ms` ;
99
- else if (! opts [prop]. match ( / ^ ( \d + | \d + \. \d + )(ms | s) $ / )) {
108
+ if (opts[prop].match (/ ^ ( \d + | \d + \. \d + ) $ / )) opts[prop] = ` ${ opts[prop]} ms` ;
109
+ else if (! validateAnimationFormField [prop](opts[prop] )) {
100
110
opts[prop] = defaultValue[prop];
101
111
}
102
112
});
103
113
104
114
const animation = animName === ' slide'
105
115
? (triggerSelector .replace (' --btn' ,' ' )
106
- .replace (/ -(\w )/ ,(l ) => l .toUpperCase ()).replaceAll (/ [-\. ] / g ,' ' ))
116
+ .replace (/ -(\w )/ ,(l ) => l .toUpperCase ()).replace (/ [-\. ] / g ,' ' ))
107
117
: animName;
108
118
jsCssAnimations .init [animation]({
109
119
trigger: triggerSelector,
@@ -132,6 +142,7 @@ aside: false
132
142
: anim-opts ="{}"
133
143
@reset-animation ="(opts) => {resetAnimation('slide', opts);}"
134
144
: fields-list ="[ 'duration', 'delay', 'staggerDelay', 'maintainSpace', 'easing', 'dimensionsTransition', 'overflowHidden'] "
145
+ : animation-form-validation ="validateAnimationFormField"
135
146
: code-snippet ="{
136
147
code: `jsCssAnimations.init.slideUp({
137
148
trigger: '.slide-up--btn',
@@ -164,6 +175,7 @@ highlight: [4]
164
175
: anim-opts ="fadeOpts"
165
176
: fields-list ="[ 'duration', 'delay', 'staggerDelay', 'maintainSpace', 'easing', 'blur', 'dimensionsTransition', 'iteration', 'direction'] "
166
177
@reset-animation ="(opts) => {resetAnimation('fade', opts);}"
178
+ : animation-form-validation ="validateAnimationFormField"
167
179
: code-snippet ="{
168
180
code: `// When 'trigger' option is omitted, .init will look for
169
181
// any element(s) that have the 'js-anim--trigger' class
@@ -192,6 +204,7 @@ highlight: [4],
192
204
: anim-opts ="collapseOpts"
193
205
: fields-list ="[ 'duration', 'delay', 'staggerDelay', 'maintainSpace', 'easing', 'dimensionsTransition', 'transfOrigin'] "
194
206
@reset-animation ="(opts) => {resetAnimation('collapse', opts);}"
207
+ : animation-form-validation ="validateAnimationFormField"
195
208
: code-snippet ="{
196
209
code: `jsCssAnimations.init.collapse({
197
210
trigger: '.collapse--btn',
0 commit comments