@tamagui/react-native-web-lite
Version:
React Native for Web
222 lines (220 loc) • 10.7 kB
JavaScript
import AnimatedWithChildren from "./AnimatedWithChildren.native.js";
import NativeAnimatedHelper from "../NativeAnimatedHelper.native.js";
import { normalizeColor, invariant } from "@tamagui/react-native-web-internals";
function _assert_this_initialized(self) {
if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return self;
}
function _call_super(_this, derived, args) {
return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
}
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor;
}
function _define_property(obj, key, value) {
return key in obj ? Object.defineProperty(obj, key, {
value,
enumerable: !0,
configurable: !0,
writable: !0
}) : obj[key] = value, obj;
}
function _get(target, property, receiver) {
return typeof Reflect < "u" && Reflect.get ? _get = Reflect.get : _get = function (target2, property2, receiver2) {
var base = _super_prop_base(target2, property2);
if (base) {
var desc = Object.getOwnPropertyDescriptor(base, property2);
return desc.get ? desc.get.call(receiver2 || target2) : desc.value;
}
}, _get(target, property, receiver || target);
}
function _get_prototype_of(o) {
return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) {
return o2.__proto__ || Object.getPrototypeOf(o2);
}, _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
if (typeof superClass != "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function");
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: !0,
configurable: !0
}
}), superClass && _set_prototype_of(subClass, superClass);
}
function _possible_constructor_return(self, call) {
return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) {
return o2.__proto__ = p2, o2;
}, _set_prototype_of(o, p);
}
function _super_prop_base(object, property) {
for (; !Object.prototype.hasOwnProperty.call(object, property) && (object = _get_prototype_of(object), object !== null););
return object;
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _is_native_reflect_construct() {
try {
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch {}
return (_is_native_reflect_construct = function () {
return !!result;
})();
}
var __DEV__ = process.env.NODE_ENV !== "production",
linear = function (t) {
return t;
};
function createInterpolation(config) {
if (config.outputRange && typeof config.outputRange[0] == "string") return createInterpolationFromStringOutputRange(config);
var outputRange = config.outputRange,
inputRange = config.inputRange;
__DEV__ && (checkInfiniteRange("outputRange", outputRange), checkInfiniteRange("inputRange", inputRange), checkValidInputRange(inputRange), invariant(inputRange.length === outputRange.length, "inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length"));
var easing = config.easing || linear,
extrapolateLeft = "extend";
config.extrapolateLeft !== void 0 ? extrapolateLeft = config.extrapolateLeft : config.extrapolate !== void 0 && (extrapolateLeft = config.extrapolate);
var extrapolateRight = "extend";
return config.extrapolateRight !== void 0 ? extrapolateRight = config.extrapolateRight : config.extrapolate !== void 0 && (extrapolateRight = config.extrapolate), function (input) {
invariant(typeof input == "number", "Cannot interpolation an input which is not a number");
var range = findRange(input, inputRange);
return interpolate(input, inputRange[range], inputRange[range + 1], outputRange[range], outputRange[range + 1], easing, extrapolateLeft, extrapolateRight);
};
}
function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight) {
var result = input;
if (result < inputMin) {
if (extrapolateLeft === "identity") return result;
extrapolateLeft === "clamp" && (result = inputMin);
}
if (result > inputMax) {
if (extrapolateRight === "identity") return result;
extrapolateRight === "clamp" && (result = inputMax);
}
return outputMin === outputMax ? outputMin : inputMin === inputMax ? input <= inputMin ? outputMin : outputMax : (inputMin === -1 / 0 ? result = -result : inputMax === 1 / 0 ? result = result - inputMin : result = (result - inputMin) / (inputMax - inputMin), result = easing(result), outputMin === -1 / 0 ? result = -result : outputMax === 1 / 0 ? result = result + outputMin : result = result * (outputMax - outputMin) + outputMin, result);
}
function colorToRgba(input) {
var normalizedColor = normalizeColor(input);
if (normalizedColor === null || typeof normalizedColor != "number") return input;
normalizedColor = normalizedColor || 0;
var r = (normalizedColor & 4278190080) >>> 24,
g = (normalizedColor & 16711680) >>> 16,
b = (normalizedColor & 65280) >>> 8,
a = (normalizedColor & 255) / 255;
return `rgba(${r}, ${g}, ${b}, ${a})`;
}
var stringShapeRegex = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
function createInterpolationFromStringOutputRange(config) {
var outputRange = config.outputRange;
invariant(outputRange.length >= 2, "Bad output range"), outputRange = outputRange.map(colorToRgba), checkPattern(outputRange);
var outputRanges = outputRange[0].match(stringShapeRegex).map(function () {
return [];
});
outputRange.forEach(function (value) {
value.match(stringShapeRegex).forEach(function (number, i) {
outputRanges[i].push(+number);
});
});
var interpolations = outputRange[0].match(stringShapeRegex).map(function (value, i) {
return createInterpolation({
...config,
outputRange: outputRanges[i]
});
}),
shouldRound = isRgbOrRgba(outputRange[0]);
return function (input) {
var i = 0;
return outputRange[0].replace(stringShapeRegex, function () {
var val = +interpolations[i++](input);
return shouldRound && (val = i < 4 ? Math.round(val) : Math.round(val * 1e3) / 1e3), String(val);
});
};
}
function isRgbOrRgba(range) {
return typeof range == "string" && range.startsWith("rgb");
}
function checkPattern(arr) {
for (var pattern = arr[0].replace(stringShapeRegex, ""), i = 1; i < arr.length; ++i) invariant(pattern === arr[i].replace(stringShapeRegex, ""), "invalid pattern " + arr[0] + " and " + arr[i]);
}
function findRange(input, inputRange) {
var i;
for (i = 1; i < inputRange.length - 1 && !(inputRange[i] >= input); ++i);
return i - 1;
}
function checkValidInputRange(arr) {
invariant(arr.length >= 2, "inputRange must have at least 2 elements");
for (var message = "inputRange must be monotonically non-decreasing " + String(arr), i = 1; i < arr.length; ++i) invariant(arr[i] >= arr[i - 1], message);
}
function checkInfiniteRange(name, arr) {
invariant(arr.length >= 2, name + " must have at least 2 elements"), invariant(arr.length !== 2 || arr[0] !== -1 / 0 || arr[1] !== 1 / 0, name + "cannot be ]-infinity;+infinity[ " + arr);
}
var AnimatedInterpolation = /* @__PURE__ */function (AnimatedWithChildren2) {
_inherits(AnimatedInterpolation2, AnimatedWithChildren2);
function AnimatedInterpolation2(parent, config) {
_class_call_check(this, AnimatedInterpolation2);
var _this;
return _this = _call_super(this, AnimatedInterpolation2), _this._parent = parent, _this._config = config, _this._interpolation = createInterpolation(config), _this;
}
return _create_class(AnimatedInterpolation2, [{
key: "__makeNative",
value: function (platformConfig) {
this._parent.__makeNative(platformConfig), _get(_get_prototype_of(AnimatedInterpolation2.prototype), "__makeNative", this).call(this, platformConfig);
}
}, {
key: "__getValue",
value: function () {
var parentValue = this._parent.__getValue();
return invariant(typeof parentValue == "number", "Cannot interpolate an input which is not a number."), this._interpolation(parentValue);
}
}, {
key: "interpolate",
value: function (config) {
return new AnimatedInterpolation2(this, config);
}
}, {
key: "__attach",
value: function () {
this._parent.__addChild(this);
}
}, {
key: "__detach",
value: function () {
this._parent.__removeChild(this), _get(_get_prototype_of(AnimatedInterpolation2.prototype), "__detach", this).call(this);
}
}, {
key: "__transformDataType",
value: function (range) {
return range.map(NativeAnimatedHelper.transformDataType);
}
}, {
key: "__getNativeConfig",
value: function () {
return __DEV__ && NativeAnimatedHelper.validateInterpolation(this._config), {
inputRange: this._config.inputRange,
// Only the `outputRange` can contain strings so we don't need to transform `inputRange` here
outputRange: this.__transformDataType(this._config.outputRange),
extrapolateLeft: this._config.extrapolateLeft || this._config.extrapolate || "extend",
extrapolateRight: this._config.extrapolateRight || this._config.extrapolate || "extend",
type: "interpolation"
};
}
}]), AnimatedInterpolation2;
}(AnimatedWithChildren);
_define_property(AnimatedInterpolation, "__createInterpolation", createInterpolation);
var AnimatedInterpolation_default = AnimatedInterpolation;
export { AnimatedInterpolation_default as default };
//# sourceMappingURL=AnimatedInterpolation.native.js.map