207 lines
5.8 KiB
JavaScript
207 lines
5.8 KiB
JavaScript
import { clsx as clsx$1 } from "clsx";
|
||
var is_array = Array.isArray;
|
||
var index_of = Array.prototype.indexOf;
|
||
var includes = Array.prototype.includes;
|
||
var array_from = Array.from;
|
||
var define_property = Object.defineProperty;
|
||
var get_descriptor = Object.getOwnPropertyDescriptor;
|
||
var object_prototype = Object.prototype;
|
||
var array_prototype = Array.prototype;
|
||
var get_prototype_of = Object.getPrototypeOf;
|
||
var is_extensible = Object.isExtensible;
|
||
var has_own_property = Object.prototype.hasOwnProperty;
|
||
const noop = () => {
|
||
};
|
||
function run_all(arr) {
|
||
for (var i = 0; i < arr.length; i++) {
|
||
arr[i]();
|
||
}
|
||
}
|
||
function deferred() {
|
||
var resolve;
|
||
var reject;
|
||
var promise = new Promise((res, rej) => {
|
||
resolve = res;
|
||
reject = rej;
|
||
});
|
||
return { promise, resolve, reject };
|
||
}
|
||
const ATTR_REGEX = /[&"<]/g;
|
||
const CONTENT_REGEX = /[&<]/g;
|
||
function escape_html(value, is_attr) {
|
||
const str = String(value ?? "");
|
||
const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
|
||
pattern.lastIndex = 0;
|
||
let escaped = "";
|
||
let last = 0;
|
||
while (pattern.test(str)) {
|
||
const i = pattern.lastIndex - 1;
|
||
const ch = str[i];
|
||
escaped += str.substring(last, i) + (ch === "&" ? "&" : ch === '"' ? """ : "<");
|
||
last = i + 1;
|
||
}
|
||
return escaped + str.substring(last);
|
||
}
|
||
const replacements = {
|
||
translate: /* @__PURE__ */ new Map([
|
||
[true, "yes"],
|
||
[false, "no"]
|
||
])
|
||
};
|
||
function attr(name, value, is_boolean = false) {
|
||
if (name === "hidden" && value !== "until-found") {
|
||
is_boolean = true;
|
||
}
|
||
if (value == null || !value && is_boolean) return "";
|
||
const normalized = has_own_property.call(replacements, name) && replacements[name].get(value) || value;
|
||
const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
|
||
return ` ${name}${assignment}`;
|
||
}
|
||
function clsx(value) {
|
||
if (typeof value === "object") {
|
||
return clsx$1(value);
|
||
} else {
|
||
return value ?? "";
|
||
}
|
||
}
|
||
const whitespace = [..." \n\r\f \v\uFEFF"];
|
||
function to_class(value, hash, directives) {
|
||
var classname = value == null ? "" : "" + value;
|
||
if (hash) {
|
||
classname = classname ? classname + " " + hash : hash;
|
||
}
|
||
if (directives) {
|
||
for (var key of Object.keys(directives)) {
|
||
if (directives[key]) {
|
||
classname = classname ? classname + " " + key : key;
|
||
} else if (classname.length) {
|
||
var len = key.length;
|
||
var a = 0;
|
||
while ((a = classname.indexOf(key, a)) >= 0) {
|
||
var b = a + len;
|
||
if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
|
||
classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1);
|
||
} else {
|
||
a = b;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return classname === "" ? null : classname;
|
||
}
|
||
function append_styles(styles, important = false) {
|
||
var separator = important ? " !important;" : ";";
|
||
var css = "";
|
||
for (var key of Object.keys(styles)) {
|
||
var value = styles[key];
|
||
if (value != null && value !== "") {
|
||
css += " " + key + ": " + value + separator;
|
||
}
|
||
}
|
||
return css;
|
||
}
|
||
function to_css_name(name) {
|
||
if (name[0] !== "-" || name[1] !== "-") {
|
||
return name.toLowerCase();
|
||
}
|
||
return name;
|
||
}
|
||
function to_style(value, styles) {
|
||
if (styles) {
|
||
var new_style = "";
|
||
var normal_styles;
|
||
var important_styles;
|
||
if (Array.isArray(styles)) {
|
||
normal_styles = styles[0];
|
||
important_styles = styles[1];
|
||
} else {
|
||
normal_styles = styles;
|
||
}
|
||
if (value) {
|
||
value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
|
||
var in_str = false;
|
||
var in_apo = 0;
|
||
var in_comment = false;
|
||
var reserved_names = [];
|
||
if (normal_styles) {
|
||
reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
|
||
}
|
||
if (important_styles) {
|
||
reserved_names.push(...Object.keys(important_styles).map(to_css_name));
|
||
}
|
||
var start_index = 0;
|
||
var name_index = -1;
|
||
const len = value.length;
|
||
for (var i = 0; i < len; i++) {
|
||
var c = value[i];
|
||
if (in_comment) {
|
||
if (c === "/" && value[i - 1] === "*") {
|
||
in_comment = false;
|
||
}
|
||
} else if (in_str) {
|
||
if (in_str === c) {
|
||
in_str = false;
|
||
}
|
||
} else if (c === "/" && value[i + 1] === "*") {
|
||
in_comment = true;
|
||
} else if (c === '"' || c === "'") {
|
||
in_str = c;
|
||
} else if (c === "(") {
|
||
in_apo++;
|
||
} else if (c === ")") {
|
||
in_apo--;
|
||
}
|
||
if (!in_comment && in_str === false && in_apo === 0) {
|
||
if (c === ":" && name_index === -1) {
|
||
name_index = i;
|
||
} else if (c === ";" || i === len - 1) {
|
||
if (name_index !== -1) {
|
||
var name = to_css_name(value.substring(start_index, name_index).trim());
|
||
if (!reserved_names.includes(name)) {
|
||
if (c !== ";") {
|
||
i++;
|
||
}
|
||
var property = value.substring(start_index, i).trim();
|
||
new_style += " " + property + ";";
|
||
}
|
||
}
|
||
start_index = i + 1;
|
||
name_index = -1;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (normal_styles) {
|
||
new_style += append_styles(normal_styles);
|
||
}
|
||
if (important_styles) {
|
||
new_style += append_styles(important_styles, true);
|
||
}
|
||
new_style = new_style.trim();
|
||
return new_style === "" ? null : new_style;
|
||
}
|
||
return value == null ? null : String(value);
|
||
}
|
||
export {
|
||
array_prototype as a,
|
||
get_prototype_of as b,
|
||
is_array as c,
|
||
deferred as d,
|
||
escape_html as e,
|
||
is_extensible as f,
|
||
get_descriptor as g,
|
||
index_of as h,
|
||
includes as i,
|
||
define_property as j,
|
||
array_from as k,
|
||
has_own_property as l,
|
||
clsx as m,
|
||
noop as n,
|
||
object_prototype as o,
|
||
to_class as p,
|
||
attr as q,
|
||
run_all as r,
|
||
to_style as t
|
||
};
|