Current section

Files

Jump to
live_motion priv static live_motion.js
Raw

priv/static/live_motion.js

var LiveMotion = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module, desc) => {
if (module && typeof module === "object" || typeof module === "function") {
for (let key of __getOwnPropNames(module))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module) => {
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
};
// node_modules/tslib/tslib.js
var require_tslib = __commonJS({
"node_modules/tslib/tslib.js"(exports, module) {
var __extends2;
var __assign2;
var __rest2;
var __decorate2;
var __param2;
var __metadata2;
var __awaiter2;
var __generator2;
var __exportStar2;
var __values2;
var __read2;
var __spread2;
var __spreadArrays2;
var __spreadArray2;
var __await2;
var __asyncGenerator2;
var __asyncDelegator2;
var __asyncValues2;
var __makeTemplateObject2;
var __importStar2;
var __importDefault2;
var __classPrivateFieldGet2;
var __classPrivateFieldSet2;
var __classPrivateFieldIn2;
var __createBinding2;
(function(factory) {
var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
if (typeof define === "function" && define.amd) {
define("tslib", ["exports"], function(exports2) {
factory(createExporter(root, createExporter(exports2)));
});
} else if (typeof module === "object" && typeof module.exports === "object") {
factory(createExporter(root, createExporter(module.exports)));
} else {
factory(createExporter(root));
}
function createExporter(exports2, previous) {
if (exports2 !== root) {
if (typeof Object.create === "function") {
Object.defineProperty(exports2, "__esModule", { value: true });
} else {
exports2.__esModule = true;
}
}
return function(id, v) {
return exports2[id] = previous ? previous(id, v) : v;
};
}
})(function(exporter) {
var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d, b) {
d.__proto__ = b;
} || function(d, b) {
for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p];
};
__extends2 = function(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
__assign2 = Object.assign || function(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;
};
__rest2 = function(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
__decorate2 = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
__param2 = function(paramIndex, decorator) {
return function(target, key) {
decorator(target, key, paramIndex);
};
};
__metadata2 = function(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
};
__awaiter2 = function(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function(resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
__generator2 = function(thisArg, body) {
var _ = { label: 0, sent: function() {
if (t[0] & 1)
throw t[1];
return t[1];
}, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([n, v]);
};
}
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];
y = 0;
} finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
};
__exportStar2 = function(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding2(o, m, p);
};
__createBinding2 = Object.create ? function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
o[k2] = m[k];
};
__values2 = function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function() {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
__read2 = function(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
} catch (error) {
e = { error };
} finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
} finally {
if (e)
throw e.error;
}
}
return ar;
};
__spread2 = function() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read2(arguments[i]));
return ar;
};
__spreadArrays2 = function() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
__spreadArray2 = function(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
__await2 = function(v) {
return this instanceof __await2 ? (this.v = v, this) : new __await2(v);
};
__asyncGenerator2 = function(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
return this;
}, i;
function verb(n) {
if (g[n])
i[n] = function(v) {
return new Promise(function(a, b) {
q.push([n, v, a, b]) > 1 || resume(n, v);
});
};
}
function resume(n, v) {
try {
step(g[n](v));
} catch (e) {
settle(q[0][3], e);
}
}
function step(r) {
r.value instanceof __await2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
}
function fulfill(value) {
resume("next", value);
}
function reject(value) {
resume("throw", value);
}
function settle(f, v) {
if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]);
}
};
__asyncDelegator2 = function(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function(e) {
throw e;
}), verb("return"), i[Symbol.iterator] = function() {
return this;
}, i;
function verb(n, f) {
i[n] = o[n] ? function(v) {
return (p = !p) ? { value: __await2(o[n](v)), done: n === "return" } : f ? f(v) : v;
} : f;
}
};
__asyncValues2 = function(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values2 === "function" ? __values2(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
return this;
}, i);
function verb(n) {
i[n] = o[n] && function(v) {
return new Promise(function(resolve, reject) {
v = o[n](v), settle(resolve, reject, v.done, v.value);
});
};
}
function settle(resolve, reject, d, v) {
Promise.resolve(v).then(function(v2) {
resolve({ value: v2, done: d });
}, reject);
}
};
__makeTemplateObject2 = function(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
} else {
cooked.raw = raw;
}
return cooked;
};
var __setModuleDefault = Object.create ? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
} : function(o, v) {
o["default"] = v;
};
__importStar2 = function(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null) {
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding2(result, mod, k);
}
__setModuleDefault(result, mod);
return result;
};
__importDefault2 = function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
};
__classPrivateFieldGet2 = function(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
__classPrivateFieldSet2 = function(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
};
__classPrivateFieldIn2 = function(state, receiver) {
if (receiver === null || typeof receiver !== "object" && typeof receiver !== "function")
throw new TypeError("Cannot use 'in' operator on non-object");
return typeof state === "function" ? receiver === state : state.has(receiver);
};
exporter("__extends", __extends2);
exporter("__assign", __assign2);
exporter("__rest", __rest2);
exporter("__decorate", __decorate2);
exporter("__param", __param2);
exporter("__metadata", __metadata2);
exporter("__awaiter", __awaiter2);
exporter("__generator", __generator2);
exporter("__exportStar", __exportStar2);
exporter("__createBinding", __createBinding2);
exporter("__values", __values2);
exporter("__read", __read2);
exporter("__spread", __spread2);
exporter("__spreadArrays", __spreadArrays2);
exporter("__spreadArray", __spreadArray2);
exporter("__await", __await2);
exporter("__asyncGenerator", __asyncGenerator2);
exporter("__asyncDelegator", __asyncDelegator2);
exporter("__asyncValues", __asyncValues2);
exporter("__makeTemplateObject", __makeTemplateObject2);
exporter("__importStar", __importStar2);
exporter("__importDefault", __importDefault2);
exporter("__classPrivateFieldGet", __classPrivateFieldGet2);
exporter("__classPrivateFieldSet", __classPrivateFieldSet2);
exporter("__classPrivateFieldIn", __classPrivateFieldIn2);
});
}
});
// js/live_motion/index.ts
var live_motion_exports = {};
__export(live_motion_exports, {
createLiveMotion: () => createLiveMotion
});
// node_modules/@motionone/utils/dist/array.es.js
function addUniqueItem(array, item) {
array.indexOf(item) === -1 && array.push(item);
}
function removeItem(arr, item) {
const index = arr.indexOf(item);
index > -1 && arr.splice(index, 1);
}
// node_modules/@motionone/utils/dist/clamp.es.js
var clamp = (min, max, v) => Math.min(Math.max(v, min), max);
// node_modules/@motionone/utils/dist/defaults.es.js
var defaults = {
duration: 0.3,
delay: 0,
endDelay: 0,
repeat: 0,
easing: "ease"
};
// node_modules/@motionone/utils/dist/is-number.es.js
var isNumber = (value) => typeof value === "number";
// node_modules/@motionone/utils/dist/is-easing-list.es.js
var isEasingList = (easing) => Array.isArray(easing) && !isNumber(easing[0]);
// node_modules/@motionone/utils/dist/wrap.es.js
var wrap = (min, max, v) => {
const rangeSize = max - min;
return ((v - min) % rangeSize + rangeSize) % rangeSize + min;
};
// node_modules/@motionone/utils/dist/easing.es.js
function getEasingForSegment(easing, i) {
return isEasingList(easing) ? easing[wrap(0, easing.length, i)] : easing;
}
// node_modules/@motionone/utils/dist/mix.es.js
var mix = (min, max, progress2) => -progress2 * min + progress2 * max + min;
// node_modules/@motionone/utils/dist/noop.es.js
var noop = () => {
};
var noopReturn = (v) => v;
// node_modules/@motionone/utils/dist/progress.es.js
var progress = (min, max, value) => max - min === 0 ? 1 : (value - min) / (max - min);
// node_modules/@motionone/utils/dist/offset.es.js
function fillOffset(offset, remaining) {
const min = offset[offset.length - 1];
for (let i = 1; i <= remaining; i++) {
const offsetProgress = progress(0, remaining, i);
offset.push(mix(min, 1, offsetProgress));
}
}
function defaultOffset(length) {
const offset = [0];
fillOffset(offset, length - 1);
return offset;
}
// node_modules/@motionone/utils/dist/interpolate.es.js
function interpolate(output, input = defaultOffset(output.length), easing = noopReturn) {
const length = output.length;
const remainder = length - input.length;
remainder > 0 && fillOffset(input, remainder);
return (t) => {
let i = 0;
for (; i < length - 2; i++) {
if (t < input[i + 1])
break;
}
let progressInRange = clamp(0, 1, progress(input[i], input[i + 1], t));
const segmentEasing = getEasingForSegment(easing, i);
progressInRange = segmentEasing(progressInRange);
return mix(output[i], output[i + 1], progressInRange);
};
}
// node_modules/@motionone/utils/dist/is-cubic-bezier.es.js
var isCubicBezier = (easing) => Array.isArray(easing) && isNumber(easing[0]);
// node_modules/@motionone/utils/dist/is-easing-generator.es.js
var isEasingGenerator = (easing) => typeof easing === "object" && Boolean(easing.createAnimation);
// node_modules/@motionone/utils/dist/is-function.es.js
var isFunction = (value) => typeof value === "function";
// node_modules/@motionone/utils/dist/is-string.es.js
var isString = (value) => typeof value === "string";
// node_modules/@motionone/utils/dist/time.es.js
var time = {
ms: (seconds) => seconds * 1e3,
s: (milliseconds) => milliseconds / 1e3
};
// node_modules/@motionone/utils/dist/velocity.es.js
function velocityPerSecond(velocity, frameDuration) {
return frameDuration ? velocity * (1e3 / frameDuration) : 0;
}
// node_modules/@motionone/easing/dist/cubic-bezier.es.js
var calcBezier = (t, a1, a2) => (((1 - 3 * a2 + 3 * a1) * t + (3 * a2 - 6 * a1)) * t + 3 * a1) * t;
var subdivisionPrecision = 1e-7;
var subdivisionMaxIterations = 12;
function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
let currentX;
let currentT;
let i = 0;
do {
currentT = lowerBound + (upperBound - lowerBound) / 2;
currentX = calcBezier(currentT, mX1, mX2) - x;
if (currentX > 0) {
upperBound = currentT;
} else {
lowerBound = currentT;
}
} while (Math.abs(currentX) > subdivisionPrecision && ++i < subdivisionMaxIterations);
return currentT;
}
function cubicBezier(mX1, mY1, mX2, mY2) {
if (mX1 === mY1 && mX2 === mY2)
return noopReturn;
const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
}
// node_modules/@motionone/easing/dist/steps.es.js
var steps = (steps2, direction = "end") => (progress2) => {
progress2 = direction === "end" ? Math.min(progress2, 0.999) : Math.max(progress2, 1e-3);
const expanded = progress2 * steps2;
const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
return clamp(0, 1, rounded / steps2);
};
// node_modules/@motionone/animation/dist/utils/easing.es.js
var namedEasings = {
ease: cubicBezier(0.25, 0.1, 0.25, 1),
"ease-in": cubicBezier(0.42, 0, 1, 1),
"ease-in-out": cubicBezier(0.42, 0, 0.58, 1),
"ease-out": cubicBezier(0, 0, 0.58, 1)
};
var functionArgsRegex = /\((.*?)\)/;
function getEasingFunction(definition) {
if (isFunction(definition))
return definition;
if (isCubicBezier(definition))
return cubicBezier(...definition);
if (namedEasings[definition])
return namedEasings[definition];
if (definition.startsWith("steps")) {
const args = functionArgsRegex.exec(definition);
if (args) {
const argsArray = args[1].split(",");
return steps(parseFloat(argsArray[0]), argsArray[1].trim());
}
}
return noopReturn;
}
// node_modules/@motionone/animation/dist/Animation.es.js
var Animation = class {
constructor(output, keyframes = [0, 1], { easing, duration: initialDuration = defaults.duration, delay = defaults.delay, endDelay = defaults.endDelay, repeat = defaults.repeat, offset, direction = "normal" } = {}) {
this.startTime = null;
this.rate = 1;
this.t = 0;
this.cancelTimestamp = null;
this.easing = noopReturn;
this.duration = 0;
this.totalDuration = 0;
this.repeat = 0;
this.playState = "idle";
this.finished = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
easing = easing || defaults.easing;
if (isEasingGenerator(easing)) {
const custom = easing.createAnimation(keyframes);
easing = custom.easing;
keyframes = custom.keyframes || keyframes;
initialDuration = custom.duration || initialDuration;
}
this.repeat = repeat;
this.easing = isEasingList(easing) ? noopReturn : getEasingFunction(easing);
this.updateDuration(initialDuration);
const interpolate$1 = interpolate(keyframes, offset, isEasingList(easing) ? easing.map(getEasingFunction) : noopReturn);
this.tick = (timestamp) => {
var _a;
delay = delay;
let t = 0;
if (this.pauseTime !== void 0) {
t = this.pauseTime;
} else {
t = (timestamp - this.startTime) * this.rate;
}
this.t = t;
t /= 1e3;
t = Math.max(t - delay, 0);
if (this.playState === "finished" && this.pauseTime === void 0) {
t = this.totalDuration;
}
const progress2 = t / this.duration;
let currentIteration = Math.floor(progress2);
let iterationProgress = progress2 % 1;
if (!iterationProgress && progress2 >= 1) {
iterationProgress = 1;
}
iterationProgress === 1 && currentIteration--;
const iterationIsOdd = currentIteration % 2;
if (direction === "reverse" || direction === "alternate" && iterationIsOdd || direction === "alternate-reverse" && !iterationIsOdd) {
iterationProgress = 1 - iterationProgress;
}
const p = t >= this.totalDuration ? 1 : Math.min(iterationProgress, 1);
const latest = interpolate$1(this.easing(p));
output(latest);
const isAnimationFinished = this.pauseTime === void 0 && (this.playState === "finished" || t >= this.totalDuration + endDelay);
if (isAnimationFinished) {
this.playState = "finished";
(_a = this.resolve) === null || _a === void 0 ? void 0 : _a.call(this, latest);
} else if (this.playState !== "idle") {
this.frameRequestId = requestAnimationFrame(this.tick);
}
};
this.play();
}
play() {
const now = performance.now();
this.playState = "running";
if (this.pauseTime !== void 0) {
this.startTime = now - this.pauseTime;
} else if (!this.startTime) {
this.startTime = now;
}
this.cancelTimestamp = this.startTime;
this.pauseTime = void 0;
this.frameRequestId = requestAnimationFrame(this.tick);
}
pause() {
this.playState = "paused";
this.pauseTime = this.t;
}
finish() {
this.playState = "finished";
this.tick(0);
}
stop() {
var _a;
this.playState = "idle";
if (this.frameRequestId !== void 0) {
cancelAnimationFrame(this.frameRequestId);
}
(_a = this.reject) === null || _a === void 0 ? void 0 : _a.call(this, false);
}
cancel() {
this.stop();
this.tick(this.cancelTimestamp);
}
reverse() {
this.rate *= -1;
}
commitStyles() {
}
updateDuration(duration) {
this.duration = duration;
this.totalDuration = duration * (this.repeat + 1);
}
get currentTime() {
return this.t;
}
set currentTime(t) {
if (this.pauseTime !== void 0 || this.rate === 0) {
this.pauseTime = t;
} else {
this.startTime = performance.now() - t / this.rate;
}
}
get playbackRate() {
return this.rate;
}
set playbackRate(rate) {
this.rate = rate;
}
};
// node_modules/@motionone/types/dist/MotionValue.es.js
var MotionValue = class {
setAnimation(animation) {
this.animation = animation;
animation === null || animation === void 0 ? void 0 : animation.finished.then(() => this.clearAnimation()).catch(() => {
});
}
clearAnimation() {
this.animation = this.generator = void 0;
}
};
// node_modules/@motionone/dom/dist/animate/data.es.js
var data = new WeakMap();
function getAnimationData(element) {
if (!data.has(element)) {
data.set(element, {
transforms: [],
values: new Map()
});
}
return data.get(element);
}
function getMotionValue(motionValues, name) {
if (!motionValues.has(name)) {
motionValues.set(name, new MotionValue());
}
return motionValues.get(name);
}
// node_modules/@motionone/dom/dist/animate/utils/transforms.es.js
var axes = ["", "X", "Y", "Z"];
var order = ["translate", "scale", "rotate", "skew"];
var transformAlias = {
x: "translateX",
y: "translateY",
z: "translateZ"
};
var rotation = {
syntax: "<angle>",
initialValue: "0deg",
toDefaultUnit: (v) => v + "deg"
};
var baseTransformProperties = {
translate: {
syntax: "<length-percentage>",
initialValue: "0px",
toDefaultUnit: (v) => v + "px"
},
rotate: rotation,
scale: {
syntax: "<number>",
initialValue: 1,
toDefaultUnit: noopReturn
},
skew: rotation
};
var transformDefinitions = new Map();
var asTransformCssVar = (name) => `--motion-${name}`;
var transforms = ["x", "y", "z"];
order.forEach((name) => {
axes.forEach((axis) => {
transforms.push(name + axis);
transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
});
});
var compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.indexOf(b);
var transformLookup = new Set(transforms);
var isTransform = (name) => transformLookup.has(name);
var addTransformToElement = (element, name) => {
if (transformAlias[name])
name = transformAlias[name];
const { transforms: transforms2 } = getAnimationData(element);
addUniqueItem(transforms2, name);
element.style.transform = buildTransformTemplate(transforms2);
};
var buildTransformTemplate = (transforms2) => transforms2.sort(compareTransformOrder).reduce(transformListToString, "").trim();
var transformListToString = (template, name) => `${template} ${name}(var(${asTransformCssVar(name)}))`;
// node_modules/@motionone/dom/dist/animate/utils/css-var.es.js
var isCssVar = (name) => name.startsWith("--");
var registeredProperties = new Set();
function registerCssVariable(name) {
if (registeredProperties.has(name))
return;
registeredProperties.add(name);
try {
const { syntax, initialValue } = transformDefinitions.has(name) ? transformDefinitions.get(name) : {};
CSS.registerProperty({
name,
inherits: false,
syntax,
initialValue
});
} catch (e) {
}
}
// node_modules/@motionone/dom/dist/animate/utils/feature-detection.es.js
var testAnimation = (keyframes, options) => document.createElement("div").animate(keyframes, options);
var featureTests = {
cssRegisterProperty: () => typeof CSS !== "undefined" && Object.hasOwnProperty.call(CSS, "registerProperty"),
waapi: () => Object.hasOwnProperty.call(Element.prototype, "animate"),
partialKeyframes: () => {
try {
testAnimation({ opacity: [1] });
} catch (e) {
return false;
}
return true;
},
finished: () => Boolean(testAnimation({ opacity: [0, 1] }, { duration: 1e-3 }).finished),
linearEasing: () => {
try {
testAnimation({ opacity: 0 }, { easing: "linear(0, 1)" });
} catch (e) {
return false;
}
return true;
}
};
var results = {};
var supports = {};
for (const key in featureTests) {
supports[key] = () => {
if (results[key] === void 0)
results[key] = featureTests[key]();
return results[key];
};
}
// node_modules/@motionone/dom/dist/animate/utils/easing.es.js
var resolution = 0.015;
var generateLinearEasingPoints = (easing, duration) => {
let points = "";
const numPoints = Math.round(duration / resolution);
for (let i = 0; i < numPoints; i++) {
points += easing(progress(0, numPoints - 1, i)) + ", ";
}
return points.substring(0, points.length - 2);
};
var convertEasing = (easing, duration) => {
if (isFunction(easing)) {
return supports.linearEasing() ? `linear(${generateLinearEasingPoints(easing, duration)})` : defaults.easing;
} else {
return isCubicBezier(easing) ? cubicBezierAsString(easing) : easing;
}
};
var cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
// node_modules/@motionone/dom/dist/animate/utils/keyframes.es.js
function hydrateKeyframes(keyframes, readInitialValue) {
for (let i = 0; i < keyframes.length; i++) {
if (keyframes[i] === null) {
keyframes[i] = i ? keyframes[i - 1] : readInitialValue();
}
}
return keyframes;
}
var keyframesList = (keyframes) => Array.isArray(keyframes) ? keyframes : [keyframes];
// node_modules/@motionone/dom/dist/animate/utils/get-style-name.es.js
function getStyleName(key) {
if (transformAlias[key])
key = transformAlias[key];
return isTransform(key) ? asTransformCssVar(key) : key;
}
// node_modules/@motionone/dom/dist/animate/style.es.js
var style = {
get: (element, name) => {
name = getStyleName(name);
let value = isCssVar(name) ? element.style.getPropertyValue(name) : getComputedStyle(element)[name];
if (!value && value !== 0) {
const definition = transformDefinitions.get(name);
if (definition)
value = definition.initialValue;
}
return value;
},
set: (element, name, value) => {
name = getStyleName(name);
if (isCssVar(name)) {
element.style.setProperty(name, value);
} else {
element.style[name] = value;
}
}
};
// node_modules/@motionone/dom/dist/animate/utils/stop-animation.es.js
function stopAnimation(animation, needsCommit = true) {
if (!animation || animation.playState === "finished")
return;
try {
if (animation.stop) {
animation.stop();
} else {
needsCommit && animation.commitStyles();
animation.cancel();
}
} catch (e) {
}
}
// node_modules/@motionone/dom/dist/animate/utils/get-unit.es.js
function getUnitConverter(keyframes, definition) {
var _a;
let toUnit = (definition === null || definition === void 0 ? void 0 : definition.toDefaultUnit) || noopReturn;
const finalKeyframe = keyframes[keyframes.length - 1];
if (isString(finalKeyframe)) {
const unit = ((_a = finalKeyframe.match(/(-?[\d.]+)([a-z%]*)/)) === null || _a === void 0 ? void 0 : _a[2]) || "";
if (unit)
toUnit = (value) => value + unit;
}
return toUnit;
}
// node_modules/@motionone/dom/dist/animate/animate-style.es.js
function getDevToolsRecord() {
return window.__MOTION_DEV_TOOLS_RECORD;
}
function animateStyle(element, key, keyframesDefinition, options = {}, AnimationPolyfill) {
const record = getDevToolsRecord();
const isRecording = options.record !== false && record;
let animation;
let { duration = defaults.duration, delay = defaults.delay, endDelay = defaults.endDelay, repeat = defaults.repeat, easing = defaults.easing, direction, offset, allowWebkitAcceleration = false } = options;
const data2 = getAnimationData(element);
const valueIsTransform = isTransform(key);
let canAnimateNatively = supports.waapi();
valueIsTransform && addTransformToElement(element, key);
const name = getStyleName(key);
const motionValue = getMotionValue(data2.values, name);
const definition = transformDefinitions.get(name);
stopAnimation(motionValue.animation, !(isEasingGenerator(easing) && motionValue.generator) && options.record !== false);
return () => {
const readInitialValue = () => {
var _a, _b;
return (_b = (_a = style.get(element, name)) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.initialValue) !== null && _b !== void 0 ? _b : 0;
};
let keyframes = hydrateKeyframes(keyframesList(keyframesDefinition), readInitialValue);
const toUnit = getUnitConverter(keyframes, definition);
if (isEasingGenerator(easing)) {
const custom = easing.createAnimation(keyframes, key !== "opacity", readInitialValue, name, motionValue);
easing = custom.easing;
keyframes = custom.keyframes || keyframes;
duration = custom.duration || duration;
}
if (isCssVar(name)) {
if (supports.cssRegisterProperty()) {
registerCssVariable(name);
} else {
canAnimateNatively = false;
}
}
if (valueIsTransform && !supports.linearEasing() && (isFunction(easing) || isEasingList(easing) && easing.some(isFunction))) {
canAnimateNatively = false;
}
if (canAnimateNatively) {
if (definition) {
keyframes = keyframes.map((value) => isNumber(value) ? definition.toDefaultUnit(value) : value);
}
if (keyframes.length === 1 && (!supports.partialKeyframes() || isRecording)) {
keyframes.unshift(readInitialValue());
}
const animationOptions = {
delay: time.ms(delay),
duration: time.ms(duration),
endDelay: time.ms(endDelay),
easing: !isEasingList(easing) ? convertEasing(easing, duration) : void 0,
direction,
iterations: repeat + 1,
fill: "both"
};
animation = element.animate({
[name]: keyframes,
offset,
easing: isEasingList(easing) ? easing.map((thisEasing) => convertEasing(thisEasing, duration)) : void 0
}, animationOptions);
if (!animation.finished) {
animation.finished = new Promise((resolve, reject) => {
animation.onfinish = resolve;
animation.oncancel = reject;
});
}
const target = keyframes[keyframes.length - 1];
animation.finished.then(() => {
style.set(element, name, target);
animation.cancel();
}).catch(noop);
if (!allowWebkitAcceleration)
animation.playbackRate = 1.000001;
} else if (AnimationPolyfill && valueIsTransform) {
keyframes = keyframes.map((value) => typeof value === "string" ? parseFloat(value) : value);
if (keyframes.length === 1) {
keyframes.unshift(parseFloat(readInitialValue()));
}
animation = new AnimationPolyfill((latest) => {
style.set(element, name, toUnit ? toUnit(latest) : latest);
}, keyframes, Object.assign(Object.assign({}, options), {
duration,
easing
}));
} else {
const target = keyframes[keyframes.length - 1];
style.set(element, name, definition && isNumber(target) ? definition.toDefaultUnit(target) : target);
}
if (isRecording) {
record(element, key, keyframes, {
duration,
delay,
easing,
repeat,
offset
}, "motion-one");
}
motionValue.setAnimation(animation);
return animation;
};
}
// node_modules/@motionone/dom/dist/animate/utils/options.es.js
var getOptions = (options, key) => options[key] ? Object.assign(Object.assign({}, options), options[key]) : Object.assign({}, options);
// node_modules/@motionone/dom/dist/utils/resolve-elements.es.js
function resolveElements(elements, selectorCache) {
var _a;
if (typeof elements === "string") {
if (selectorCache) {
(_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : selectorCache[elements] = document.querySelectorAll(elements);
elements = selectorCache[elements];
} else {
elements = document.querySelectorAll(elements);
}
} else if (elements instanceof Element) {
elements = [elements];
}
return Array.from(elements || []);
}
// node_modules/tslib/modules/index.js
var import_tslib = __toModule(require_tslib());
var {
__extends,
__assign,
__rest,
__decorate,
__param,
__metadata,
__awaiter,
__generator,
__exportStar,
__createBinding,
__values,
__read,
__spread,
__spreadArrays,
__spreadArray,
__await,
__asyncGenerator,
__asyncDelegator,
__asyncValues,
__makeTemplateObject,
__importStar,
__importDefault,
__classPrivateFieldGet,
__classPrivateFieldSet,
__classPrivateFieldIn
} = import_tslib.default;
// node_modules/hey-listen/dist/hey-listen.es.js
var warning = function() {
};
var invariant = function() {
};
if (true) {
warning = function(check, message) {
if (!check && typeof console !== "undefined") {
console.warn(message);
}
};
invariant = function(check, message) {
if (!check) {
throw new Error(message);
}
};
}
// node_modules/@motionone/generators/dist/utils/velocity.es.js
var sampleT = 5;
function calcGeneratorVelocity(resolveValue, t, current) {
const prevT = Math.max(t - sampleT, 0);
return velocityPerSecond(current - resolveValue(prevT), t - prevT);
}
// node_modules/@motionone/generators/dist/spring/defaults.es.js
var defaults2 = {
stiffness: 100,
damping: 10,
mass: 1
};
// node_modules/@motionone/generators/dist/spring/utils.es.js
var calcDampingRatio = (stiffness = defaults2.stiffness, damping = defaults2.damping, mass = defaults2.mass) => damping / (2 * Math.sqrt(stiffness * mass));
// node_modules/@motionone/generators/dist/utils/has-reached-target.es.js
function hasReachedTarget(origin, target, current) {
return origin < target && current >= target || origin > target && current <= target;
}
// node_modules/@motionone/generators/dist/spring/index.es.js
var spring = ({ stiffness = defaults2.stiffness, damping = defaults2.damping, mass = defaults2.mass, from = 0, to = 1, velocity = 0, restSpeed = 2, restDistance = 0.5 } = {}) => {
velocity = velocity ? time.s(velocity) : 0;
const state = {
done: false,
hasReachedTarget: false,
current: from,
target: to
};
const initialDelta = to - from;
const undampedAngularFreq = Math.sqrt(stiffness / mass) / 1e3;
const dampingRatio = calcDampingRatio(stiffness, damping, mass);
let resolveSpring;
if (dampingRatio < 1) {
const angularFreq = undampedAngularFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
resolveSpring = (t) => to - Math.exp(-dampingRatio * undampedAngularFreq * t) * ((-velocity + dampingRatio * undampedAngularFreq * initialDelta) / angularFreq * Math.sin(angularFreq * t) + initialDelta * Math.cos(angularFreq * t));
} else {
resolveSpring = (t) => {
return to - Math.exp(-undampedAngularFreq * t) * (initialDelta + (-velocity + undampedAngularFreq * initialDelta) * t);
};
}
return (t) => {
state.current = resolveSpring(t);
const currentVelocity = t === 0 ? velocity : calcGeneratorVelocity(resolveSpring, t, state.current);
const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
const isBelowDisplacementThreshold = Math.abs(to - state.current) <= restDistance;
state.done = isBelowVelocityThreshold && isBelowDisplacementThreshold;
state.hasReachedTarget = hasReachedTarget(from, to, state.current);
return state;
};
};
// node_modules/@motionone/generators/dist/glide/index.es.js
var glide = ({ from = 0, velocity = 0, power = 0.8, decay = 0.325, bounceDamping, bounceStiffness, changeTarget, min, max, restDistance = 0.5, restSpeed }) => {
decay = time.ms(decay);
const state = {
hasReachedTarget: false,
done: false,
current: from,
target: from
};
const isOutOfBounds = (v) => min !== void 0 && v < min || max !== void 0 && v > max;
const nearestBoundary = (v) => {
if (min === void 0)
return max;
if (max === void 0)
return min;
return Math.abs(min - v) < Math.abs(max - v) ? min : max;
};
let amplitude = power * velocity;
const ideal = from + amplitude;
const target = changeTarget === void 0 ? ideal : changeTarget(ideal);
state.target = target;
if (target !== ideal)
amplitude = target - from;
const calcDelta = (t) => -amplitude * Math.exp(-t / decay);
const calcLatest = (t) => target + calcDelta(t);
const applyFriction = (t) => {
const delta = calcDelta(t);
const latest = calcLatest(t);
state.done = Math.abs(delta) <= restDistance;
state.current = state.done ? target : latest;
};
let timeReachedBoundary;
let spring$1;
const checkCatchBoundary = (t) => {
if (!isOutOfBounds(state.current))
return;
timeReachedBoundary = t;
spring$1 = spring({
from: state.current,
to: nearestBoundary(state.current),
velocity: calcGeneratorVelocity(calcLatest, t, state.current),
damping: bounceDamping,
stiffness: bounceStiffness,
restDistance,
restSpeed
});
};
checkCatchBoundary(0);
return (t) => {
let hasUpdatedFrame = false;
if (!spring$1 && timeReachedBoundary === void 0) {
hasUpdatedFrame = true;
applyFriction(t);
checkCatchBoundary(t);
}
if (timeReachedBoundary !== void 0 && t > timeReachedBoundary) {
state.hasReachedTarget = true;
return spring$1(t - timeReachedBoundary);
} else {
state.hasReachedTarget = false;
!hasUpdatedFrame && applyFriction(t);
return state;
}
};
};
// node_modules/@motionone/generators/dist/utils/pregenerate-keyframes.es.js
var timeStep = 10;
var maxDuration = 1e4;
function pregenerateKeyframes(generator, toUnit = noopReturn) {
let overshootDuration = void 0;
let timestamp = timeStep;
let state = generator(0);
const keyframes = [toUnit(state.current)];
while (!state.done && timestamp < maxDuration) {
state = generator(timestamp);
keyframes.push(toUnit(state.done ? state.target : state.current));
if (overshootDuration === void 0 && state.hasReachedTarget) {
overshootDuration = timestamp;
}
timestamp += timeStep;
}
const duration = timestamp - timeStep;
if (keyframes.length === 1)
keyframes.push(state.current);
return {
keyframes,
duration: duration / 1e3,
overshootDuration: (overshootDuration !== null && overshootDuration !== void 0 ? overshootDuration : duration) / 1e3
};
}
// node_modules/@motionone/dom/dist/easing/create-generator-easing.es.js
function canGenerate(value) {
return isNumber(value) && !isNaN(value);
}
function getAsNumber(value) {
return isString(value) ? parseFloat(value) : value;
}
function createGeneratorEasing(createGenerator) {
const keyframesCache = new WeakMap();
return (options = {}) => {
const generatorCache = new Map();
const getGenerator = (from = 0, to = 100, velocity = 0, isScale = false) => {
const key = `${from}-${to}-${velocity}-${isScale}`;
if (!generatorCache.has(key)) {
generatorCache.set(key, createGenerator(Object.assign({
from,
to,
velocity,
restSpeed: isScale ? 0.05 : 2,
restDistance: isScale ? 0.01 : 0.5
}, options)));
}
return generatorCache.get(key);
};
const getKeyframes = (generator, toUnit) => {
if (!keyframesCache.has(generator)) {
keyframesCache.set(generator, pregenerateKeyframes(generator, toUnit));
}
return keyframesCache.get(generator);
};
return {
createAnimation: (keyframes, shouldGenerate = true, getOrigin, name, motionValue) => {
let settings;
let origin;
let target;
let velocity = 0;
let toUnit = noopReturn;
const numKeyframes = keyframes.length;
if (shouldGenerate) {
toUnit = getUnitConverter(keyframes, name ? transformDefinitions.get(getStyleName(name)) : void 0);
const targetDefinition = keyframes[numKeyframes - 1];
target = getAsNumber(targetDefinition);
if (numKeyframes > 1 && keyframes[0] !== null) {
origin = getAsNumber(keyframes[0]);
} else {
const prevGenerator = motionValue === null || motionValue === void 0 ? void 0 : motionValue.generator;
if (prevGenerator) {
const { animation, generatorStartTime } = motionValue;
const startTime = (animation === null || animation === void 0 ? void 0 : animation.startTime) || generatorStartTime || 0;
const currentTime = (animation === null || animation === void 0 ? void 0 : animation.currentTime) || performance.now() - startTime;
const prevGeneratorCurrent = prevGenerator(currentTime).current;
origin = prevGeneratorCurrent;
velocity = calcGeneratorVelocity((t) => prevGenerator(t).current, currentTime, prevGeneratorCurrent);
} else if (getOrigin) {
origin = getAsNumber(getOrigin());
}
}
}
if (canGenerate(origin) && canGenerate(target)) {
const generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
settings = Object.assign(Object.assign({}, getKeyframes(generator, toUnit)), { easing: "linear" });
if (motionValue) {
motionValue.generator = generator;
motionValue.generatorStartTime = performance.now();
}
}
if (!settings) {
const keyframesMetadata = getKeyframes(getGenerator(0, 100));
settings = {
easing: "ease",
duration: keyframesMetadata.overshootDuration
};
}
return settings;
}
};
};
}
// node_modules/@motionone/dom/dist/easing/spring/index.es.js
var spring2 = createGeneratorEasing(spring);
// node_modules/@motionone/dom/dist/easing/glide/index.es.js
var glide2 = createGeneratorEasing(glide);
// node_modules/@motionone/dom/dist/gestures/in-view.es.js
var thresholds = {
any: 0,
all: 1
};
function inView(elementOrSelector, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
if (typeof IntersectionObserver === "undefined") {
return () => {
};
}
const elements = resolveElements(elementOrSelector);
const activeIntersections = new WeakMap();
const onIntersectionChange = (entries) => {
entries.forEach((entry) => {
const onEnd = activeIntersections.get(entry.target);
if (entry.isIntersecting === Boolean(onEnd))
return;
if (entry.isIntersecting) {
const newOnEnd = onStart(entry);
if (isFunction(newOnEnd)) {
activeIntersections.set(entry.target, newOnEnd);
} else {
observer.unobserve(entry.target);
}
} else if (onEnd) {
onEnd(entry);
activeIntersections.delete(entry.target);
}
});
};
const observer = new IntersectionObserver(onIntersectionChange, {
root,
rootMargin,
threshold: typeof amount === "number" ? amount : thresholds[amount]
});
elements.forEach((element) => observer.observe(element));
return () => observer.disconnect();
}
// node_modules/@motionone/dom/dist/state/utils/has-changed.es.js
function hasChanged(a, b) {
if (typeof a !== typeof b)
return true;
if (Array.isArray(a) && Array.isArray(b))
return !shallowCompare(a, b);
return a !== b;
}
function shallowCompare(next, prev) {
const prevLength = prev.length;
if (prevLength !== next.length)
return false;
for (let i = 0; i < prevLength; i++) {
if (prev[i] !== next[i])
return false;
}
return true;
}
// node_modules/@motionone/dom/dist/state/utils/is-variant.es.js
function isVariant(definition) {
return typeof definition === "object";
}
// node_modules/@motionone/dom/dist/state/utils/resolve-variant.es.js
function resolveVariant(definition, variants) {
if (isVariant(definition)) {
return definition;
} else if (definition && variants) {
return variants[definition];
}
}
// node_modules/@motionone/dom/dist/state/utils/schedule.es.js
var scheduled = void 0;
function processScheduledAnimations() {
if (!scheduled)
return;
const generators = scheduled.sort(compareByDepth).map(fireAnimateUpdates);
generators.forEach(fireNext);
generators.forEach(fireNext);
scheduled = void 0;
}
function scheduleAnimation(state) {
if (!scheduled) {
scheduled = [state];
requestAnimationFrame(processScheduledAnimations);
} else {
addUniqueItem(scheduled, state);
}
}
function unscheduleAnimation(state) {
scheduled && removeItem(scheduled, state);
}
var compareByDepth = (a, b) => a.getDepth() - b.getDepth();
var fireAnimateUpdates = (state) => state.animateUpdates();
var fireNext = (iterator) => iterator.next();
// node_modules/@motionone/dom/dist/state/utils/events.es.js
var motionEvent = (name, target) => new CustomEvent(name, { detail: { target } });
function dispatchPointerEvent(element, name, event) {
element.dispatchEvent(new CustomEvent(name, { detail: { originalEvent: event } }));
}
function dispatchViewEvent(element, name, entry) {
element.dispatchEvent(new CustomEvent(name, { detail: { originalEntry: entry } }));
}
// node_modules/@motionone/dom/dist/state/gestures/in-view.es.js
var inView2 = {
isActive: (options) => Boolean(options.inView),
subscribe: (element, { enable, disable }, { inViewOptions = {} }) => {
const { once } = inViewOptions, viewOptions = __rest(inViewOptions, ["once"]);
return inView(element, (enterEntry) => {
enable();
dispatchViewEvent(element, "viewenter", enterEntry);
if (!once) {
return (leaveEntry) => {
disable();
dispatchViewEvent(element, "viewleave", leaveEntry);
};
}
}, viewOptions);
}
};
// node_modules/@motionone/dom/dist/state/gestures/hover.es.js
var mouseEvent = (element, name, action) => (event) => {
if (event.pointerType && event.pointerType !== "mouse")
return;
action();
dispatchPointerEvent(element, name, event);
};
var hover = {
isActive: (options) => Boolean(options.hover),
subscribe: (element, { enable, disable }) => {
const onEnter = mouseEvent(element, "hoverstart", enable);
const onLeave = mouseEvent(element, "hoverend", disable);
element.addEventListener("pointerenter", onEnter);
element.addEventListener("pointerleave", onLeave);
return () => {
element.removeEventListener("pointerenter", onEnter);
element.removeEventListener("pointerleave", onLeave);
};
}
};
// node_modules/@motionone/dom/dist/state/gestures/press.es.js
var press = {
isActive: (options) => Boolean(options.press),
subscribe: (element, { enable, disable }) => {
const onPointerUp = (event) => {
disable();
dispatchPointerEvent(element, "pressend", event);
window.removeEventListener("pointerup", onPointerUp);
};
const onPointerDown = (event) => {
enable();
dispatchPointerEvent(element, "pressstart", event);
window.addEventListener("pointerup", onPointerUp);
};
element.addEventListener("pointerdown", onPointerDown);
return () => {
element.removeEventListener("pointerdown", onPointerDown);
window.removeEventListener("pointerup", onPointerUp);
};
}
};
// node_modules/@motionone/dom/dist/state/index.es.js
var gestures = { inView: inView2, hover, press };
var stateTypes = ["initial", "animate", ...Object.keys(gestures), "exit"];
var mountedStates = new WeakMap();
function createMotionState(options = {}, parent) {
let element;
let depth = parent ? parent.getDepth() + 1 : 0;
const activeStates = { initial: true, animate: true };
const gestureSubscriptions = {};
const context = {};
for (const name of stateTypes) {
context[name] = typeof options[name] === "string" ? options[name] : parent === null || parent === void 0 ? void 0 : parent.getContext()[name];
}
const initialVariantSource = options.initial === false ? "animate" : "initial";
let _a = resolveVariant(options[initialVariantSource] || context[initialVariantSource], options.variants) || {}, target = __rest(_a, ["transition"]);
const baseTarget = Object.assign({}, target);
function* animateUpdates() {
var _a2, _b;
const prevTarget = target;
target = {};
const animationOptions = {};
for (const name of stateTypes) {
if (!activeStates[name])
continue;
const variant = resolveVariant(options[name]);
if (!variant)
continue;
for (const key in variant) {
if (key === "transition")
continue;
target[key] = variant[key];
animationOptions[key] = getOptions((_b = (_a2 = variant.transition) !== null && _a2 !== void 0 ? _a2 : options.transition) !== null && _b !== void 0 ? _b : {}, key);
}
}
const allTargetKeys = new Set([
...Object.keys(target),
...Object.keys(prevTarget)
]);
const animationFactories = [];
allTargetKeys.forEach((key) => {
var _a3;
if (target[key] === void 0) {
target[key] = baseTarget[key];
}
if (hasChanged(prevTarget[key], target[key])) {
(_a3 = baseTarget[key]) !== null && _a3 !== void 0 ? _a3 : baseTarget[key] = style.get(element, key);
animationFactories.push(animateStyle(element, key, target[key], animationOptions[key], Animation));
}
});
yield;
const animations = animationFactories.map((factory) => factory()).filter(Boolean);
if (!animations.length)
return;
const animationTarget = target;
element.dispatchEvent(motionEvent("motionstart", animationTarget));
Promise.all(animations.map((animation) => animation.finished)).then(() => {
element.dispatchEvent(motionEvent("motioncomplete", animationTarget));
}).catch(noop);
}
const setGesture = (name, isActive) => () => {
activeStates[name] = isActive;
scheduleAnimation(state);
};
const updateGestureSubscriptions = () => {
for (const name in gestures) {
const isGestureActive = gestures[name].isActive(options);
const remove = gestureSubscriptions[name];
if (isGestureActive && !remove) {
gestureSubscriptions[name] = gestures[name].subscribe(element, {
enable: setGesture(name, true),
disable: setGesture(name, false)
}, options);
} else if (!isGestureActive && remove) {
remove();
delete gestureSubscriptions[name];
}
}
};
const state = {
update: (newOptions) => {
if (!element)
return;
options = newOptions;
updateGestureSubscriptions();
scheduleAnimation(state);
},
setActive: (name, isActive) => {
if (!element)
return;
activeStates[name] = isActive;
scheduleAnimation(state);
},
animateUpdates,
getDepth: () => depth,
getTarget: () => target,
getOptions: () => options,
getContext: () => context,
mount: (newElement) => {
invariant(Boolean(newElement), "Animation state must be mounted with valid Element");
element = newElement;
mountedStates.set(element, state);
updateGestureSubscriptions();
return () => {
mountedStates.delete(element);
unscheduleAnimation(state);
for (const key in gestureSubscriptions) {
gestureSubscriptions[key]();
}
};
},
isMounted: () => Boolean(element)
};
return state;
}
// js/live_motion/helpers.ts
function compactObj(obj) {
return Object.entries(obj).reduce((acc, [key, value]) => {
if (value !== void 0 && value !== null) {
acc[key] = value;
}
return acc;
}, {});
}
// js/live_motion/live_motion.ts
var MAX_TRANSITION_DURATION = 10 * 1e3;
var DEFAULT_TRANSITION_DURATION = 300;
var motionHooks = new WeakMap();
function createMotionHook() {
function registerEventHandlers() {
const config = this.getConfig();
this.eventHandlers = {
motionstart: () => {
liveSocket.execJS(this.el, config == null ? void 0 : config.on_motion_start);
},
motioncomplete: () => {
liveSocket.execJS(this.el, config == null ? void 0 : config.on_motion_complete);
}
};
if (config == null ? void 0 : config.on_motion_start) {
this.el.addEventListener("motionstart", this.eventHandlers["motionstart"]);
}
if (config == null ? void 0 : config.on_motion_complete) {
this.el.addEventListener("motioncomplete", this.eventHandlers["motioncomplete"]);
}
}
return {
Motion: {
getConfig() {
return getMotionConfig(this.el);
},
getMotionOptions() {
var _a;
const config = this.getConfig();
if (!config) {
return void 0;
}
const translateEasing = () => {
const { transition: transition2 } = config;
if ((transition2 == null ? void 0 : transition2.easing) === "spring") {
return spring2();
}
if ((transition2 == null ? void 0 : transition2.easing) === "glide") {
return glide2();
}
if (typeof (transition2 == null ? void 0 : transition2.easing) === "object" && !Array.isArray(transition2.easing)) {
if (transition2.easing.spring) {
return spring2(transition2.easing.spring);
}
if (transition2.easing.glide) {
return glide2(transition2.easing.glide);
}
}
return transition2 == null ? void 0 : transition2.easing;
};
const transition = ((_a = config.transition) == null ? void 0 : _a.easing) ? __spreadProps(__spreadValues({}, config.transition), { easing: translateEasing() }) : config.transition;
const options = {
initial: config.initial,
animate: config.animate,
exit: config.exit,
hover: config.hover,
press: config.press,
inView: config.in_view,
inViewOptions: config.in_view_options,
transition
};
return compactObj(options);
},
maybeAnimate(options) {
const { force = false } = options || {};
const config = this.getConfig();
const motionOptions = this.getMotionOptions();
if (this.state && motionOptions && config && (!(config == null ? void 0 : config.defer) || force)) {
this.state.update(motionOptions);
}
},
mounted() {
motionHooks.set(this.el, this);
registerEventHandlers.apply(this);
this.state = createMotionState(this.getMotionOptions());
this.cleanup = this.state.mount(this.el);
this.maybeAnimate();
},
destroyed() {
var _a;
if (this.eventHandlers) {
Object.entries(this.eventHandlers).forEach(([e, fn]) => this.el.removeEventListener(e, fn));
}
motionHooks.delete(this.el);
(_a = this.cleanup) == null ? void 0 : _a.call(this);
},
updated() {
this.maybeAnimate();
}
}
};
}
function handleMotionUpdates(from, to) {
if (from.dataset.motion) {
if (from.getAttribute("style") === null) {
to.removeAttribute("style");
} else {
to.setAttribute("style", from.getAttribute("style"));
}
}
}
function createLiveMotion() {
window.addEventListener("live_motion:animate", (e) => {
const { target } = e;
const motion = motionHooks.get(target);
if (!motion && liveSocket.isDebugEnabled()) {
console.warn("[LiveMotion] Motion element not found. Did you forget to make your target a LiveMotion.motion component?");
}
if (motion) {
motion.maybeAnimate({ force: true });
}
});
window.addEventListener("live_motion:hide", (e) => {
var _a;
const { target } = e;
const motion = motionHooks.get(target);
if (!motion && liveSocket.isDebugEnabled()) {
console.warn("[LiveMotion] Motion element not found. Did you forget to make your target a LiveMotion.motion component?");
}
if (motion) {
const duration = getDuration((_a = motion.getConfig()) == null ? void 0 : _a.transition);
liveSocket.transition(duration, () => {
var _a2;
const motion2 = motionHooks.get(target);
if (motion2) {
motion2.el.addEventListener("motioncomplete", () => motion2.el.style.display = "none", {
once: true
});
(_a2 = motion2.state) == null ? void 0 : _a2.setActive("exit", true);
}
});
}
});
window.addEventListener("live_motion:show", (e) => {
var _a, _b, _c;
const { target, detail } = e;
const motion = motionHooks.get(target);
if (!motion && liveSocket.isDebugEnabled()) {
console.warn("[LiveMotion] Motion element not found. Did you forget to make your target a LiveMotion.motion component?");
}
if (motion) {
motion.el.style.display = (_a = detail == null ? void 0 : detail.display) != null ? _a : "block";
(_b = motion.state) == null ? void 0 : _b.setActive("exit", false);
(_c = motion.state) == null ? void 0 : _c.setActive("animate", true);
}
});
window.addEventListener("live_motion:toggle", (e) => {
var _a, _b;
const { target } = e;
const motion = motionHooks.get(target);
if (!motion && liveSocket.isDebugEnabled()) {
console.warn("[LiveMotion] Motion element not found. Did you forget to make your target a LiveMotion.motion component?");
}
if (motion) {
const toggle = motion.el.hasAttribute("data-motion-toggle") ? motion.el.dataset.motionToggle === "true" : !((_a = motion.getConfig()) == null ? void 0 : _a.defer);
motion.el.dataset.motionToggle = String(!toggle);
(_b = motion.state) == null ? void 0 : _b.setActive("exit", toggle);
}
});
return {
hook: createMotionHook(),
handleMotionUpdates
};
}
function getDuration(transition) {
const isPhysics = transition && (typeof transition.easing === "object" && !Array.isArray(transition.easing) || transition.easing === "spring" || transition.easing === "glide");
if (isPhysics && typeof (transition == null ? void 0 : transition.duration) !== "undefined") {
return transition.duration * 1e3;
}
return isPhysics ? MAX_TRANSITION_DURATION : typeof (transition == null ? void 0 : transition.duration) !== "undefined" ? transition.duration * 1e3 : DEFAULT_TRANSITION_DURATION;
}
function getMotionConfig(el) {
return el.dataset.motion ? JSON.parse(el.dataset.motion) : void 0;
}
return live_motion_exports;
})();