var h = Object.defineProperty;
var $ = (o, t, e) => t in o ? h(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
var d = (o, t, e) => $(o, typeof t != "symbol" ? t + "" : t, e);
import { cloneDeep as p, isObject as x, isNumber as b } from "lodash";
import { PX_PROPERTIES as O } from "../const/css.mjs";
class S {
  /**
   * 将 JSON 转换为 CSS 样式对象
   * @param styleJson - 需要转换的 JSON 对象
   * @param prefix - 前缀
   * @returns 转换后的 CSS 样式对象
   */
  static json2cssObject(t, e = "", c = !1) {
    const s = {}, f = (i, u) => {
      if (!x(i))
        return {};
      Object.keys(i).forEach((n) => {
        const r = i[n], g = n.replace(/([a-zA-Z])(?=[A-Z])/g, "$1-").toLowerCase(), a = u + g;
        if (n === "backgroundImage") {
          s[a] = `url('${r}')`;
          return;
        }
        if (O.includes(n) && b(r)) {
          s[a] = `${r}px`;
          return;
        }
        if (n === "color" && r.includes("linear-gradient")) {
          s[u + "-webkit-background-clip"] = "text", s[u + "color"] = "transparent", s[u + "background-image"] = r;
          return;
        }
        if (n === "textShadow") {
          const l = r;
          l.show && Object.assign(s, {
            [a]: `${l.x}px ${l.y}px ${l.value}px ${l.color}`
          });
          return;
        }
        if (x(r)) {
          c && f(r, a + "-");
          return;
        }
        n === "fontFamily" && this.installFont(r), s[a] = String(r);
      });
    };
    return f(p(t), ""), this.addPrefixToKeys(s, e);
  }
  static addPrefixToKeys(t, e) {
    if (!e)
      return t;
    const c = {};
    for (const s in t)
      c[`${e}${s}`] = t[s];
    return c;
  }
  /**
   * 安装字体
   * @param fontFamily - 字体名称
   */
  static installFont(t) {
    if (t && t.startsWith("SHJ-")) {
      let e = !1;
      if (document.fonts.forEach((c) => {
        c.family === t && (e = !0);
      }), !e) {
        const c = t.slice(4, t.lastIndexOf("-")), s = c.slice(0, c.lastIndexOf("-")), f = t.slice(
          t.lastIndexOf("-") + 1,
          t.length
        ), i = new FontFace(
          t,
          `url(${this.fontUrl}/${s}/${c}.${f})`
        );
        document.fonts.add(i), i.load().then(() => {
        }).catch(() => {
        });
      }
    }
  }
}
/**
 * 字体地址
 */
d(S, "fontUrl", "https://lganv-1304359499.cos.ap-beijing.myqcloud.com/lg_cos_static/fonts");
export {
  S as Utils
};
