UNPKG

@tamagui/react-native-web-lite

Version:
224 lines (223 loc) 10.9 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var TimingAnimation_exports = {}; __export(TimingAnimation_exports, { default: () => TimingAnimation_default }); module.exports = __toCommonJS(TimingAnimation_exports); var import_Easing = __toESM(require("../Easing")), import_Animation = __toESM(require("./Animation")), import_NativeAnimatedHelper = require("../NativeAnimatedHelper"); 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 _construct(Parent, args, Class) { return _is_native_reflect_construct() ? _construct = Reflect.construct : _construct = function(Parent2, args2, Class2) { var a = [ null ]; a.push.apply(a, args2); var Constructor = Function.bind.apply(Parent2, a), instance = new Constructor(); return Class2 && _set_prototype_of(instance, Class2.prototype), instance; }, _construct.apply(null, arguments); } 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 _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } 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 _wrap_native_super(Class) { var _cache = typeof Map == "function" ? /* @__PURE__ */ new Map() : void 0; return _wrap_native_super = function(Class2) { if (Class2 === null || !_is_native_function(Class2)) return Class2; if (typeof Class2 != "function") throw new TypeError("Super expression must either be null or a function"); if (typeof _cache < "u") { if (_cache.has(Class2)) return _cache.get(Class2); _cache.set(Class2, Wrapper); } function Wrapper() { return _construct(Class2, arguments, _get_prototype_of(this).constructor); } return Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _set_prototype_of(Wrapper, Class2); }, _wrap_native_super(Class); } 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 _easeInOut; function easeInOut() { return _easeInOut || (_easeInOut = import_Easing.default.inOut(import_Easing.default.ease)), _easeInOut; } var TimingAnimation = /* @__PURE__ */ function(Animation2) { "use strict"; _inherits(TimingAnimation2, Animation2); function TimingAnimation2(config) { _class_call_check(this, TimingAnimation2); var _this; _this = _call_super(this, TimingAnimation2), _define_property(_this, "_startTime", void 0), _define_property(_this, "_fromValue", void 0), _define_property(_this, "_toValue", void 0), _define_property(_this, "_duration", void 0), _define_property(_this, "_delay", void 0), _define_property(_this, "_easing", void 0), _define_property(_this, "_onUpdate", void 0), _define_property(_this, "_animationFrame", void 0), _define_property(_this, "_timeout", void 0), _define_property(_this, "_useNativeDriver", void 0), _define_property(_this, "_platformConfig", void 0), _this._toValue = config.toValue; var _config_easing; _this._easing = (_config_easing = config.easing) !== null && _config_easing !== void 0 ? _config_easing : easeInOut(); var _config_duration; _this._duration = (_config_duration = config.duration) !== null && _config_duration !== void 0 ? _config_duration : 500; var _config_delay; _this._delay = (_config_delay = config.delay) !== null && _config_delay !== void 0 ? _config_delay : 0; var _config_iterations; _this.__iterations = (_config_iterations = config.iterations) !== null && _config_iterations !== void 0 ? _config_iterations : 1, _this._useNativeDriver = (0, import_NativeAnimatedHelper.shouldUseNativeDriver)(config), _this._platformConfig = config.platformConfig; var _config_isInteraction; return _this.__isInteraction = (_config_isInteraction = config.isInteraction) !== null && _config_isInteraction !== void 0 ? _config_isInteraction : !_this._useNativeDriver, _this; } return _create_class(TimingAnimation2, [ { key: "__getNativeAnimationConfig", value: function() { for (var frameDuration = 16.666666666666668, frames = [], numFrames = Math.round(this._duration / frameDuration), frame = 0; frame < numFrames; frame++) frames.push(this._easing(frame / numFrames)); return frames.push(this._easing(1)), { type: "frames", frames, toValue: this._toValue, iterations: this.__iterations, platformConfig: this._platformConfig }; } }, { key: "start", value: function(fromValue, onUpdate, onEnd, previousAnimation, animatedValue) { var _this = this; this.__active = !0, this._fromValue = fromValue, this._onUpdate = onUpdate, this.__onEnd = onEnd; var start2 = function() { _this._duration === 0 && !_this._useNativeDriver ? (_this._onUpdate(_this._toValue), _this.__debouncedOnEnd({ finished: !0 })) : (_this._startTime = Date.now(), _this._useNativeDriver ? _this.__startNativeAnimation(animatedValue) : _this._animationFrame = requestAnimationFrame( // $FlowFixMe[method-unbinding] added when improving typing for this parameters _this.onUpdate.bind(_this) )); }; this._delay ? this._timeout = setTimeout(start2, this._delay) : start2(); } }, { key: "onUpdate", value: function() { var now = Date.now(); if (now >= this._startTime + this._duration) { this._duration === 0 ? this._onUpdate(this._toValue) : this._onUpdate(this._fromValue + this._easing(1) * (this._toValue - this._fromValue)), this.__debouncedOnEnd({ finished: !0 }); return; } this._onUpdate(this._fromValue + this._easing((now - this._startTime) / this._duration) * (this._toValue - this._fromValue)), this.__active && (this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this))); } }, { key: "stop", value: function() { _get(_get_prototype_of(TimingAnimation2.prototype), "stop", this).call(this), this.__active = !1, clearTimeout(this._timeout), global.cancelAnimationFrame(this._animationFrame), this.__debouncedOnEnd({ finished: !1 }); } } ]), TimingAnimation2; }(_wrap_native_super(import_Animation.default)), TimingAnimation_default = TimingAnimation; //# sourceMappingURL=TimingAnimation.js.map