203 lines
6.8 KiB
JavaScript
203 lines
6.8 KiB
JavaScript
(function (root, factory) {
|
|
var presets = factory();
|
|
|
|
if (typeof module === 'object' && module.exports) {
|
|
module.exports = presets;
|
|
}
|
|
|
|
if (root) {
|
|
root.templateAnimationPresets = presets;
|
|
}
|
|
})(typeof window !== 'undefined' ? window : (typeof globalThis !== 'undefined' ? globalThis : this), function () {
|
|
function option(value, label) {
|
|
return { value: value, label: label };
|
|
}
|
|
|
|
function formatLabel(value) {
|
|
return String(value || '')
|
|
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
.replace(/[_-]+/g, ' ')
|
|
.replace(/\s+/g, ' ')
|
|
.trim()
|
|
.replace(/\b\w/g, function (letter) {
|
|
return letter.toUpperCase();
|
|
});
|
|
}
|
|
|
|
function buildAllValues(groups, extraValues) {
|
|
var values = [];
|
|
var seen = Object.create(null);
|
|
|
|
function addEntry(entry) {
|
|
if (!entry || typeof entry !== 'object' || !entry.value || seen[entry.value]) {
|
|
return;
|
|
}
|
|
|
|
seen[entry.value] = true;
|
|
values.push(entry.value);
|
|
}
|
|
|
|
Object.keys(groups).forEach(function (groupName) {
|
|
(groups[groupName] || []).forEach(function (entry) {
|
|
if (Array.isArray(entry)) {
|
|
entry.forEach(addEntry);
|
|
return;
|
|
}
|
|
|
|
addEntry(entry);
|
|
});
|
|
});
|
|
|
|
(extraValues || []).forEach(function (value) {
|
|
if (!value || seen[value]) {
|
|
return;
|
|
}
|
|
|
|
seen[value] = true;
|
|
values.push(value);
|
|
});
|
|
|
|
return values;
|
|
}
|
|
|
|
function buildLookup(values) {
|
|
var lookup = Object.create(null);
|
|
|
|
values.forEach(function (value) {
|
|
var key = String(value || '').trim().toLowerCase();
|
|
if (key && !lookup[key]) {
|
|
lookup[key] = value;
|
|
}
|
|
});
|
|
|
|
return lookup;
|
|
}
|
|
|
|
function normalizeValue(value, lookup) {
|
|
var raw = String(value || '').trim();
|
|
if (!raw) {
|
|
return 'none';
|
|
}
|
|
|
|
return lookup[raw.toLowerCase()] || 'none';
|
|
}
|
|
|
|
function splitAnimateCssValues(values) {
|
|
var groups = {
|
|
intro: [],
|
|
outro: [],
|
|
attentionSeekers: []
|
|
};
|
|
|
|
(values || []).forEach(function (value) {
|
|
if (!value || value === 'none') {
|
|
return;
|
|
}
|
|
|
|
if (value.indexOf('In') !== -1) {
|
|
groups.intro.push(value);
|
|
return;
|
|
}
|
|
|
|
if (value.indexOf('Out') !== -1) {
|
|
groups.outro.push(value);
|
|
return;
|
|
}
|
|
|
|
groups.attentionSeekers.push(value);
|
|
});
|
|
|
|
return groups;
|
|
}
|
|
|
|
function buildCuratedBasic(values) {
|
|
return [option('none', 'None')].concat(values.map(function (value) {
|
|
return option(value, formatLabel(value));
|
|
}));
|
|
}
|
|
|
|
var animateCssValues = [
|
|
'none',
|
|
'bounce', 'flash', 'pulse', 'rubberBand', 'shakeX', 'shakeY', 'headShake', 'swing', 'tada', 'wobble', 'jello', 'heartBeat',
|
|
'backInDown', 'backInLeft', 'backInRight', 'backInUp',
|
|
'backOutDown', 'backOutLeft', 'backOutRight', 'backOutUp',
|
|
'bounceIn', 'bounceInDown', 'bounceInLeft', 'bounceInRight', 'bounceInUp',
|
|
'bounceOut', 'bounceOutDown', 'bounceOutLeft', 'bounceOutRight', 'bounceOutUp',
|
|
'fadeIn', 'fadeInDown', 'fadeInDownBig', 'fadeInLeft', 'fadeInLeftBig', 'fadeInRight', 'fadeInRightBig', 'fadeInUp', 'fadeInUpBig', 'fadeInTopLeft', 'fadeInTopRight', 'fadeInBottomLeft', 'fadeInBottomRight',
|
|
'fadeOut', 'fadeOutDown', 'fadeOutDownBig', 'fadeOutLeft', 'fadeOutLeftBig', 'fadeOutRight', 'fadeOutRightBig', 'fadeOutUp', 'fadeOutUpBig', 'fadeOutTopLeft', 'fadeOutTopRight', 'fadeOutBottomLeft', 'fadeOutBottomRight',
|
|
'flip', 'flipInX', 'flipInY', 'flipOutX', 'flipOutY',
|
|
'lightSpeedInLeft', 'lightSpeedInRight', 'lightSpeedOutLeft', 'lightSpeedOutRight',
|
|
'rotateIn', 'rotateInDownLeft', 'rotateInDownRight', 'rotateInUpLeft', 'rotateInUpRight',
|
|
'rotateOut', 'rotateOutDownLeft', 'rotateOutDownRight', 'rotateOutUpLeft', 'rotateOutUpRight',
|
|
'hinge', 'jackInTheBox', 'rollIn', 'rollOut',
|
|
'zoomIn', 'zoomInDown', 'zoomInLeft', 'zoomInRight', 'zoomInUp',
|
|
'zoomOut', 'zoomOutDown', 'zoomOutLeft', 'zoomOutRight', 'zoomOutUp',
|
|
'slideInDown', 'slideInLeft', 'slideInRight', 'slideInUp',
|
|
'slideOutDown', 'slideOutLeft', 'slideOutRight', 'slideOutUp'
|
|
];
|
|
|
|
var splitValues = splitAnimateCssValues(animateCssValues);
|
|
|
|
var basic = {
|
|
intro: [
|
|
option('none', 'None'),
|
|
option('fadeIn', formatLabel('fadeIn')),
|
|
option('fadeInDown', formatLabel('fadeInDown')),
|
|
option('fadeInLeft', formatLabel('fadeInLeft')),
|
|
option('fadeInRight', formatLabel('fadeInRight')),
|
|
option('fadeInUp', formatLabel('fadeInUp')),
|
|
option('zoomIn', formatLabel('zoomIn')),
|
|
option('zoomInDown', formatLabel('zoomInDown')),
|
|
option('zoomInLeft', formatLabel('zoomInLeft')),
|
|
option('zoomInRight', formatLabel('zoomInRight')),
|
|
option('zoomInUp', formatLabel('zoomInUp')),
|
|
option('slideInDown', formatLabel('slideInDown')),
|
|
option('slideInLeft', formatLabel('slideInLeft')),
|
|
option('slideInRight', formatLabel('slideInRight')),
|
|
option('slideInUp', formatLabel('slideInUp'))
|
|
],
|
|
outro: [
|
|
option('none', 'None'),
|
|
option('fadeOut', formatLabel('fadeOut')),
|
|
option('fadeOutDown', formatLabel('fadeOutDown')),
|
|
option('fadeOutLeft', formatLabel('fadeOutLeft')),
|
|
option('fadeOutRight', formatLabel('fadeOutRight')),
|
|
option('fadeOutUp', formatLabel('fadeOutUp')),
|
|
option('zoomOut', formatLabel('zoomOut')),
|
|
option('zoomOutDown', formatLabel('zoomOutDown')),
|
|
option('zoomOutLeft', formatLabel('zoomOutLeft')),
|
|
option('zoomOutRight', formatLabel('zoomOutRight')),
|
|
option('zoomOutUp', formatLabel('zoomOutUp')),
|
|
option('slideOutDown', formatLabel('slideOutDown')),
|
|
option('slideOutLeft', formatLabel('slideOutLeft')),
|
|
option('slideOutRight', formatLabel('slideOutRight')),
|
|
option('slideOutUp', formatLabel('slideOutUp'))
|
|
],
|
|
attentionSeekers: buildCuratedBasic(['flash', 'pulse', 'rubberBand', 'shakeX', 'shakeY', 'swing', 'tada', 'wobble', 'jello', 'heartBeat', 'bounce'])
|
|
};
|
|
|
|
var advanced = {
|
|
intro: buildCuratedBasic(splitValues.intro),
|
|
outro: buildCuratedBasic(splitValues.outro),
|
|
attentionSeekers: buildCuratedBasic(splitValues.attentionSeekers)
|
|
};
|
|
|
|
var lookup = buildLookup(buildAllValues({ basic: [basic.intro, basic.outro, basic.attentionSeekers], advanced: [advanced.intro, advanced.outro, advanced.attentionSeekers] }));
|
|
|
|
function normalize(value) {
|
|
return normalizeValue(value, lookup);
|
|
}
|
|
|
|
function isAnimateCssPreset(value) {
|
|
return animateCssValues.indexOf(normalizeValue(value, buildLookup(animateCssValues))) !== -1;
|
|
}
|
|
|
|
return {
|
|
basic: basic,
|
|
advanced: advanced,
|
|
animateCssValues: animateCssValues,
|
|
allValues: buildAllValues({ basic: [basic.intro, basic.outro, basic.attentionSeekers], advanced: [advanced.intro, advanced.outro, advanced.attentionSeekers] }),
|
|
normalize: normalize,
|
|
isAnimateCssPreset: isAnimateCssPreset
|
|
};
|
|
}); |