Packages

A drop-in replacement for notification system in Phoenix.

Retired package: Deprecated - Please use shino

Current section

Files

Jump to
phoenix_notif priv static phoenix_notif.js
Raw

priv/static/phoenix_notif.js

var PhoenixNotif = (() => {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// phoenix_notif/index.js
var phoenix_notif_exports = {};
__export(phoenix_notif_exports, {
default: () => createPhoenixNotifHook
});
// node_modules/@motionone/utils/dist/array.es.js
function addUniqueItem(array, item) {
array.indexOf(item) === -1 && array.push(item);
}
// 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/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", autoplay = true } = {}) {
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);
}
};
if (autoplay)
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/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/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 = /* @__PURE__ */ new WeakMap();
function getAnimationData(element) {
if (!data.has(element)) {
data.set(element, {
transforms: [],
values: /* @__PURE__ */ 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 = /* @__PURE__ */ 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 = /* @__PURE__ */ 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, persist = false, direction, offset, allowWebkitAcceleration = false, autoplay = true } = 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(() => {
if (persist)
return;
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);
if (animation && !autoplay)
animation.pause();
return animation;
};
}
// node_modules/@motionone/dom/dist/animate/utils/options.es.js
var getOptions = (options, key) => (
/**
* TODO: Make test for this
* Always return a new object otherwise delay is overwritten by results of stagger
* and this results in no stagger
*/
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/@motionone/dom/dist/animate/utils/controls.es.js
var createAnimation = (factory) => factory();
var withControls = (animationFactory, options, duration = defaults.duration) => {
return new Proxy({
animations: animationFactory.map(createAnimation).filter(Boolean),
duration,
options
}, controls);
};
var getActiveAnimation = (state) => state.animations[0];
var controls = {
get: (target, key) => {
const activeAnimation = getActiveAnimation(target);
switch (key) {
case "duration":
return target.duration;
case "currentTime":
return time.s((activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key]) || 0);
case "playbackRate":
case "playState":
return activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key];
case "finished":
if (!target.finished) {
target.finished = Promise.all(target.animations.map(selectFinished)).catch(noop);
}
return target.finished;
case "stop":
return () => {
target.animations.forEach((animation) => stopAnimation(animation));
};
case "forEachNative":
return (callback) => {
target.animations.forEach((animation) => callback(animation, target));
};
default:
return typeof (activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key]) === "undefined" ? void 0 : () => target.animations.forEach((animation) => animation[key]());
}
},
set: (target, key, value) => {
switch (key) {
case "currentTime":
value = time.ms(value);
case "playbackRate":
for (let i = 0; i < target.animations.length; i++) {
target.animations[i][key] = value;
}
return true;
}
return false;
}
};
var selectFinished = (animation) => animation.finished;
// node_modules/@motionone/dom/dist/utils/stagger.es.js
function resolveOption(option, i, total) {
return isFunction(option) ? option(i, total) : option;
}
// node_modules/@motionone/dom/dist/animate/create-animate.es.js
function createAnimate(AnimatePolyfill) {
return function animate3(elements, keyframes, options = {}) {
elements = resolveElements(elements);
const numElements = elements.length;
invariant(Boolean(numElements), "No valid element provided.");
invariant(Boolean(keyframes), "No keyframes defined.");
const animationFactories = [];
for (let i = 0; i < numElements; i++) {
const element = elements[i];
for (const key in keyframes) {
const valueOptions = getOptions(options, key);
valueOptions.delay = resolveOption(valueOptions.delay, i, numElements);
const animation = animateStyle(element, key, keyframes[key], valueOptions, AnimatePolyfill);
animationFactories.push(animation);
}
}
return withControls(
animationFactories,
options,
/**
* TODO:
* If easing is set to spring or glide, duration will be dynamically
* generated. Ideally we would dynamically generate this from
* animation.effect.getComputedTiming().duration but this isn't
* supported in iOS13 or our number polyfill. Perhaps it's possible
* to Proxy animations returned from animateStyle that has duration
* as a getter.
*/
options.duration
);
};
}
// node_modules/@motionone/dom/dist/animate/index.es.js
var animate = createAnimate(Animation);
// node_modules/motion/dist/animate.es.js
function animateProgress(target, options = {}) {
return withControls([
() => {
const animation = new Animation(target, [0, 1], options);
animation.finished.catch(() => {
});
return animation;
}
], options, options.duration);
}
function animate2(target, keyframesOrOptions, options) {
const factory = isFunction(target) ? animateProgress : animate;
return factory(target, keyframesOrOptions, options);
}
// phoenix_notif/index.js
function isHidden(el) {
if (el === null) {
return true;
}
return el.offsetParent === null;
}
function doAnimations(notificationGroupId, notificationToRemove, {
gapBetweenNotifications = 15,
maxShownNotifications = 3
} = {}) {
const notificationGroup = document.querySelector(`#${notificationGroupId}`);
const notifications = Array.from(
notificationGroup.querySelectorAll(`[phx-hook="PhoenixNotif"]`)
).filter((n) => !isHidden(n)).filter((n) => n !== notificationToRemove).reverse().map((notification, index) => {
notification.new = notification.order == void 0;
notification.order = index;
return notification;
});
for (let notification of notifications) {
if (notification.order >= maxShownNotifications) {
notification.classList.remove("pointer-events-auto");
} else {
notification.classList.add("pointer-events-auto");
}
notification.style.zIndex = `${50 - 1 - notification.order}`;
const direction = notificationGroup.dataset.position.startsWith("bottom_") ? "-" : "";
let y = 0;
for (let i = 0; i < notification.order; i++) {
y += notifications[i].offsetHeight + gapBetweenNotifications;
}
const targetY = `${direction}${y}`;
notification.targetY = targetY;
const opacity = notification.order >= maxShownNotifications ? 0 : 1;
const keyframes = { y: [`${targetY}px`], opacity: [opacity] };
if (notification.new) {
const y2 = notification.offsetHeight + gapBetweenNotifications;
const oppositeDirection = direction === "-" ? "" : "-";
keyframes.y.unshift(`${oppositeDirection}${y2}px`);
keyframes.opacity.unshift(0);
}
animate2(notification, keyframes, {
duration: 0.55,
easing: [0.22, 1, 0.36, 1]
});
}
}
function animateOut(notificationGroupId, notification) {
return __async(this, null, function* () {
const notificationGroup = document.querySelector(`#${notificationGroupId}`);
const direction = notificationGroup.dataset.position.startsWith("bottom_") ? "-" : "";
const y = notification.order > 0 ? Math.abs(Math.abs(notification.targetY) - notification.offsetHeight) : 0;
console.log(y);
const animation = animate2(
notification,
{ y: `${direction}${y}px`, opacity: 0 },
{
y: {
duration: 0.3,
easing: "ease-out"
},
opacity: {
duration: 0.2,
easing: "ease-out"
}
}
);
yield animation.finished;
});
}
function createPhoenixNotifHook(animateOptions) {
return {
mounted() {
const type = this.type();
const groupId = this.groupId();
const duration = this.duration();
this.el.addEventListener("notification-dismiss", (event) => __async(this, null, function* () {
event.stopPropagation();
doAnimations(groupId, this.el, animateOptions);
yield animateOut(groupId, this.el);
switch (type) {
case "flash":
this.el.remove();
break;
case "lv-flash":
this.el.remove();
const kind = this.kind();
this.pushEvent("lv:clear-flash", { key: kind });
break;
case "lv-toast":
this.el.remove();
this.pushEventTo(`#${this.groupId()}`, "clear-toast", { id: this.el.id });
break;
default:
throw `unknown notification type - ${type}`;
}
}));
doAnimations(groupId, null, animateOptions);
if (duration > 0) {
window.setTimeout(() => {
const event = new Event("notification-dismiss");
this.el.dispatchEvent(event);
}, duration);
}
},
updated() {
const keyframes = { y: [`${this.el.targetY}px`] };
animate2(this.el, keyframes, { duration: 0 });
},
type() {
return this.el.dataset.type;
},
kind() {
return this.el.dataset.kind;
},
groupId() {
return this.el.dataset.groupId;
},
duration() {
return Number.parseInt(this.el.dataset.duration);
}
};
}
return __toCommonJS(phoenix_notif_exports);
})();