youtuber-blog-frontend/build/server/chunks/index-De6aia-x.js

365 lines
11 KiB
JavaScript
Raw Normal View History

2024-06-21 23:07:29 +00:00
import { w as withGet } from './index3-BO7d7Sb-.js';
import { w as writable } from './index2-BO_DJNQw.js';
import { g as get_store_value, h as createEventDispatcher, j as split_css_unit, k as identity } from './lifecycle-Cykl3Eqn.js';
import { a as cubicOut } from './button-PuTSnXRo.js';
const overridable = (_store, onChange) => {
const store = withGet(_store);
const update = (updater, sideEffect) => {
store.update((curr) => {
const next = updater(curr);
let res = next;
if (onChange) {
res = onChange({ curr, next });
}
sideEffect?.(res);
return res;
});
};
const set = (curr) => {
update(() => curr);
};
return {
...store,
update,
set
};
};
function toWritableStores(properties) {
const result = {};
Object.keys(properties).forEach((key) => {
const propertyKey = key;
const value = properties[propertyKey];
result[propertyKey] = withGet(writable(value));
});
return result;
}
function createBitAttrs(bit, parts) {
const attrs = {};
parts.forEach((part) => {
attrs[part] = {
[`data-${bit}-${part}`]: ""
};
});
return (part) => attrs[part];
}
function disabledAttrs(disabled) {
return disabled ? { "aria-disabled": "true", "data-disabled": "" } : { "aria-disabled": void 0, "data-disabled": void 0 };
}
function createDispatcher() {
const dispatch = createEventDispatcher();
return (e) => {
const { originalEvent } = e.detail;
const { cancelable } = e;
const type = originalEvent.type;
const shouldContinue = dispatch(type, { originalEvent, currentTarget: originalEvent.currentTarget }, { cancelable });
if (!shouldContinue) {
e.preventDefault();
}
};
}
function removeUndefined(obj) {
const result = {};
for (const key in obj) {
const value = obj[key];
if (value !== void 0) {
result[key] = value;
}
}
return result;
}
function getOptionUpdater(options) {
return function(key, value) {
if (value === void 0)
return;
const store = options[key];
if (store) {
store.set(value);
}
};
}
function fade(node, { delay = 0, duration = 400, easing = identity } = {}) {
const o = +getComputedStyle(node).opacity;
return {
delay,
duration,
easing,
css: (t) => `opacity: ${t * o}`
};
}
function fly(node, { delay = 0, duration = 400, easing = cubicOut, x = 0, y = 0, opacity = 0 } = {}) {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const transform = style.transform === "none" ? "" : style.transform;
const od = target_opacity * (1 - opacity);
const [xValue, xUnit] = split_css_unit(x);
const [yValue, yUnit] = split_css_unit(y);
return {
delay,
duration,
easing,
css: (t, u) => `
transform: ${transform} translate(${(1 - t) * xValue}${xUnit}, ${(1 - t) * yValue}${yUnit});
opacity: ${target_opacity - od * u}`
};
}
function slide(node, { delay = 0, duration = 400, easing = cubicOut, axis = "y" } = {}) {
const style = getComputedStyle(node);
const opacity = +style.opacity;
const primary_property = axis === "y" ? "height" : "width";
const primary_property_value = parseFloat(style[primary_property]);
const secondary_properties = axis === "y" ? ["top", "bottom"] : ["left", "right"];
const capitalized_secondary_properties = secondary_properties.map(
(e) => `${e[0].toUpperCase()}${e.slice(1)}`
);
const padding_start_value = parseFloat(style[`padding${capitalized_secondary_properties[0]}`]);
const padding_end_value = parseFloat(style[`padding${capitalized_secondary_properties[1]}`]);
const margin_start_value = parseFloat(style[`margin${capitalized_secondary_properties[0]}`]);
const margin_end_value = parseFloat(style[`margin${capitalized_secondary_properties[1]}`]);
const border_width_start_value = parseFloat(
style[`border${capitalized_secondary_properties[0]}Width`]
);
const border_width_end_value = parseFloat(
style[`border${capitalized_secondary_properties[1]}Width`]
);
return {
delay,
duration,
easing,
css: (t) => `overflow: hidden;opacity: ${Math.min(t * 20, 1) * opacity};${primary_property}: ${t * primary_property_value}px;padding-${secondary_properties[0]}: ${t * padding_start_value}px;padding-${secondary_properties[1]}: ${t * padding_end_value}px;margin-${secondary_properties[0]}: ${t * margin_start_value}px;margin-${secondary_properties[1]}: ${t * margin_end_value}px;border-${secondary_properties[0]}-width: ${t * border_width_start_value}px;border-${secondary_properties[1]}-width: ${t * border_width_end_value}px;`
};
}
function scale(node, { delay = 0, duration = 400, easing = cubicOut, start = 0, opacity = 0 } = {}) {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const transform = style.transform === "none" ? "" : style.transform;
const sd = 1 - start;
const od = target_opacity * (1 - opacity);
return {
delay,
duration,
easing,
css: (_t, u) => `
transform: ${transform} scale(${1 - sd * u});
opacity: ${target_opacity - od * u}
`
};
}
function cn(...classes) {
return classes.filter(Boolean).join(" ");
}
const isBrowser = typeof document !== "undefined";
function clientWritable(initialValue) {
const store = writable(initialValue);
function set(value) {
if (isBrowser) {
store.set(value);
}
}
function update(updater) {
if (isBrowser) {
store.update(updater);
}
}
return {
subscribe: store.subscribe,
set,
update
};
}
let toastsCounter = 0;
function createToastState() {
const toasts = clientWritable([]);
const heights = clientWritable([]);
function addToast(data) {
toasts.update((prev) => [data, ...prev]);
}
function create(data) {
const { message: message2, ...rest } = data;
const id = typeof data?.id === "number" || data.id && data.id?.length > 0 ? data.id : toastsCounter++;
const dismissable = data.dismissable === void 0 ? true : data.dismissable;
const type = data.type === void 0 ? "default" : data.type;
const $toasts = get_store_value(toasts);
const alreadyExists = $toasts.find((toast2) => {
return toast2.id === id;
});
if (alreadyExists) {
toasts.update((prev) => prev.map((toast2) => {
if (toast2.id === id) {
return {
...toast2,
...data,
id,
title: message2,
dismissable,
type,
updated: true
};
}
return {
...toast2,
updated: false
};
}));
} else {
addToast({ ...rest, id, title: message2, dismissable, type });
}
return id;
}
function dismiss(id) {
if (id === void 0) {
toasts.set([]);
return;
}
toasts.update((prev) => prev.filter((toast2) => toast2.id !== id));
return id;
}
function message(message2, data) {
return create({ ...data, type: "default", message: message2 });
}
function error(message2, data) {
return create({ ...data, type: "error", message: message2 });
}
function success(message2, data) {
return create({ ...data, type: "success", message: message2 });
}
function info(message2, data) {
return create({ ...data, type: "info", message: message2 });
}
function warning(message2, data) {
return create({ ...data, type: "warning", message: message2 });
}
function loading(message2, data) {
return create({ ...data, type: "loading", message: message2 });
}
function promise(promise2, data) {
if (!data) {
return;
}
let id = void 0;
if (data.loading !== void 0) {
id = create({
...data,
promise: promise2,
type: "loading",
message: data.loading
});
}
const p = promise2 instanceof Promise ? promise2 : promise2();
let shouldDismiss = id !== void 0;
p.then((response) => {
if (response && typeof response.ok === "boolean" && !response.ok) {
shouldDismiss = false;
const message2 = typeof data.error === "function" ? (
// @ts-expect-error: Incorrect response type
data.error(`HTTP error! status: ${response.status}`)
) : data.error;
create({ id, type: "error", message: message2 });
} else if (data.success !== void 0) {
shouldDismiss = false;
const message2 = (
// @ts-expect-error: TODO: Better function checking
typeof data.success === "function" ? data.success(response) : data.success
);
create({ id, type: "success", message: message2 });
}
}).catch((error2) => {
if (data.error !== void 0) {
shouldDismiss = false;
const message2 = (
// @ts-expect-error: TODO: Better function checking
typeof data.error === "function" ? data.error(error2) : data.error
);
create({ id, type: "error", message: message2 });
}
}).finally(() => {
if (shouldDismiss) {
dismiss(id);
id = void 0;
}
data.finally?.();
});
return id;
}
function custom(component, data) {
const id = data?.id || toastsCounter++;
create({ component, id, ...data });
return id;
}
function removeHeight(id) {
heights.update((prev) => prev.filter((height) => height.toastId !== id));
}
function setHeight(data) {
const exists = get_store_value(heights).find((el) => el.toastId === data.toastId);
if (exists === void 0) {
heights.update((prev) => [data, ...prev]);
return;
}
heights.update((prev) => prev.map((el) => {
if (el.toastId === data.toastId) {
return data;
} else {
return el;
}
}));
}
function reset() {
toasts.set([]);
heights.set([]);
}
return {
// methods
create,
addToast,
dismiss,
message,
error,
success,
info,
warning,
loading,
promise,
custom,
removeHeight,
setHeight,
reset,
// stores
toasts,
heights
};
}
const toastState = createToastState();
function toastFunction(message, data) {
return toastState.create({
message,
...data
});
}
const basicToast = toastFunction;
const toast = Object.assign(basicToast, {
success: toastState.success,
info: toastState.info,
warning: toastState.warning,
error: toastState.error,
custom: toastState.custom,
message: toastState.message,
promise: toastState.promise,
dismiss: toastState.dismiss,
loading: toastState.loading
});
const useEffect = (subscribe) => ({ subscribe });
let urlAlphabet =
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
let nanoid = (size = 21) => {
let id = '';
let i = size;
while (i--) {
id += urlAlphabet[(Math.random() * 64) | 0];
}
return id
};
export { createBitAttrs as a, fade as b, createDispatcher as c, disabledAttrs as d, cn as e, fly as f, getOptionUpdater as g, toWritableStores as h, toast as i, slide as j, nanoid as n, overridable as o, removeUndefined as r, scale as s, toastState as t, useEffect as u };
//# sourceMappingURL=index-De6aia-x.js.map