const i = /[\\/:*?"<>|\x00-\x1f]/g;
function a(t) {
  if (!t || !t.trim()) return "theme";
  const e = t.trim().replace(i, "-").replace(/^\.+/, "").replace(/[. ]+$/, "");
  return e.length === 0 ? "theme" : e.length > 80 ? e.slice(0, 80) : e;
}
function c(t, r) {
  const e = URL.createObjectURL(t);
  try {
    const o = document.createElement("a");
    o.href = e, o.download = `${a(r)}.smartstack-theme.json`, document.body.appendChild(o), o.click(), o.remove();
  } finally {
    URL.revokeObjectURL(e);
  }
}
async function m(t) {
  if (t.size > 20971520)
    throw new n("importTooLarge", { maxBytes: 20971520, actual: t.size });
  let r;
  try {
    r = await t.text();
  } catch {
    throw new n("importInvalidFile");
  }
  let e;
  try {
    e = JSON.parse(r);
  } catch {
    throw new n("importInvalidFile");
  }
  if (!s(e))
    throw new n("importInvalidFile");
  if (typeof e.schemaVersion != "number" || e.schemaVersion <= 0 || e.schemaVersion > 1)
    throw new n("importVersionUnsupported", {
      schemaVersion: e.schemaVersion,
      supportedVersion: 1
    });
  if (!e.theme || typeof e.theme.name != "string" || e.theme.name.length === 0 || e.theme.name.length > 80)
    throw new n("importInvalidFile");
  if (!Array.isArray(e.presets))
    throw new n("importInvalidFile");
  return e;
}
class n extends Error {
  i18nKey;
  context;
  constructor(r, e) {
    super(r), this.i18nKey = r, this.context = e, this.name = "ThemeImportError";
  }
}
function s(t) {
  return typeof t == "object" && t !== null;
}
export {
  n as T,
  m as p,
  a as s,
  c as t
};
//# sourceMappingURL=themeExport-BLRx1foC.js.map
