UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

211 lines (190 loc) 7.79 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var heyListen_es = require('../../../hey-listen/dist/hey-listen.es.js'); require('../../../framesync/dist/framesync.es.js'); var styleValueTypes_es = require('../../../style-value-types/dist/style-value-types.es.js'); var easing_es = require('../../easing/dist/easing.es.js'); var zeroPoint = { x: 0, y: 0, z: 0 }; var isNum = function (v) { return typeof v === 'number'; }; var curryRange = (function (func) { return function (min, max, v) { return (v !== undefined ? func(min, max, v) : function (cv) { return func(min, max, cv); }); }; }); var clamp = function (min, max, v) { return Math.min(Math.max(v, min), max); }; var clamp$1 = curryRange(clamp); var isPoint = (function (point) { return point.hasOwnProperty('x') && point.hasOwnProperty('y'); }); var isPoint3D = (function (point) { return isPoint(point) && point.hasOwnProperty('z'); }); var distance1D = function (a, b) { return Math.abs(a - b); }; var distance = (function (a, b) { if (b === void 0) { b = zeroPoint; } if (isNum(a) && isNum(b)) { return distance1D(a, b); } else if (isPoint(a) && isPoint(b)) { var xDelta = distance1D(a.x, b.x); var yDelta = distance1D(a.y, b.y); var zDelta = isPoint3D(a) && isPoint3D(b) ? distance1D(a.z, b.z) : 0; return Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2) + Math.pow(zDelta, 2)); } return 0; }); var progress = (function (from, to, value) { var toFromDifference = to - from; return toFromDifference === 0 ? 1 : (value - from) / toFromDifference; }); var mix = (function (from, to, progress) { return -progress * from + progress * to + from; }); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var mixLinearColor = function (from, to, v) { var fromExpo = from * from; var toExpo = to * to; return Math.sqrt(Math.max(0, v * (toExpo - fromExpo) + fromExpo)); }; var colorTypes = [styleValueTypes_es.hex, styleValueTypes_es.rgba, styleValueTypes_es.hsla]; var getColorType = function (v) { return colorTypes.find(function (type) { return type.test(v); }); }; var notAnimatable = function (color$$1) { return "'" + color$$1 + "' is not an animatable color. Use the equivalent color code instead."; }; var mixColor = (function (from, to) { var fromColorType = getColorType(from); var toColorType = getColorType(to); heyListen_es.invariant(!!fromColorType, notAnimatable(from)); heyListen_es.invariant(!!toColorType, notAnimatable(to)); heyListen_es.invariant(fromColorType.transform === toColorType.transform, 'Both colors must be hex/RGBA, OR both must be HSLA.'); var fromColor = fromColorType.parse(from); var toColor = toColorType.parse(to); var blended = __assign({}, fromColor); var mixFunc = fromColorType === styleValueTypes_es.hsla ? mix : mixLinearColor; return function (v) { for (var key in blended) { if (key !== 'alpha') { blended[key] = mixFunc(fromColor[key], toColor[key], v); } } blended.alpha = mix(fromColor.alpha, toColor.alpha, v); return fromColorType.transform(blended); }; }); var combineFunctions = function (a, b) { return function (v) { return b(a(v)); }; }; var pipe = (function () { var transformers = []; for (var _i = 0; _i < arguments.length; _i++) { transformers[_i] = arguments[_i]; } return transformers.reduce(combineFunctions); }); function getMixer(origin, target) { if (isNum(origin)) { return function (v) { return mix(origin, target, v); }; } else if (styleValueTypes_es.color.test(origin)) { return mixColor(origin, target); } else { return mixComplex(origin, target); } } var mixArray = function (from, to) { var output = from.slice(); var numValues = output.length; var blendValue = from.map(function (fromThis, i) { return getMixer(fromThis, to[i]); }); return function (v) { for (var i = 0; i < numValues; i++) { output[i] = blendValue[i](v); } return output; }; }; function analyse(value) { var parsed = styleValueTypes_es.complex.parse(value); var numValues = parsed.length; var numNumbers = 0; var numRGB = 0; var numHSL = 0; for (var i = 0; i < numValues; i++) { if (numNumbers || typeof parsed[i] === 'number') { numNumbers++; } else { if (parsed[i].hue !== undefined) { numHSL++; } else { numRGB++; } } } return { parsed: parsed, numNumbers: numNumbers, numRGB: numRGB, numHSL: numHSL }; } var mixComplex = function (origin, target) { var template = styleValueTypes_es.complex.createTransformer(target); var originStats = analyse(origin); var targetStats = analyse(target); heyListen_es.invariant(originStats.numHSL === targetStats.numHSL && originStats.numRGB === targetStats.numRGB && originStats.numNumbers >= targetStats.numNumbers, "Complex values '" + origin + "' and '" + target + "' too different to mix. Ensure all colors are of the same type."); return pipe(mixArray(originStats.parsed, targetStats.parsed), template); }; var velocityPerSecond = (function (velocity, frameDuration) { return frameDuration ? velocity * (1000 / frameDuration) : 0; }); var clampProgress = clamp$1(0, 1); exports.anticipate = easing_es.anticipate; exports.backIn = easing_es.backIn; exports.backInOut = easing_es.backInOut; exports.backOut = easing_es.backOut; exports.circIn = easing_es.circIn; exports.circInOut = easing_es.circInOut; exports.circOut = easing_es.circOut; exports.createAnticipateEasing = easing_es.createAnticipateEasing; exports.createBackIn = easing_es.createBackIn; exports.createExpoIn = easing_es.createExpoIn; exports.cubicBezier = easing_es.cubicBezier; exports.easeIn = easing_es.easeIn; exports.easeInOut = easing_es.easeInOut; exports.easeOut = easing_es.easeOut; exports.linear = easing_es.linear; exports.mirrored = easing_es.mirrored; exports.reversed = easing_es.reversed; exports.clamp = clamp$1; exports.distance = distance; exports.isPoint = isPoint; exports.isPoint3D = isPoint3D; exports.mix = mix; exports.mixArray = mixArray; exports.mixColor = mixColor; exports.mixComplex = mixComplex; exports.pipe = pipe; exports.progress = progress; exports.velocityPerSecond = velocityPerSecond;