'use strict';

/*!
 * @techmely/utils
 * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
 * MIT Licensed
 */


// src/invariant.ts
var prefix = "Invariant failed";
function invariant(condition, message) {
  if (condition) {
    return;
  }
  if (typeof message === "string" || typeof message === "function") {
    const provided = typeof message === "function" ? message() : message;
    const value = provided ? `${prefix}: ${provided}` : prefix;
    throw new Error(value);
  }
  if (message)
    throw message;
  throw new Error(prefix);
}

// src/isBrowser.ts
function isBrowser() {
  return typeof window !== "undefined";
}

// src/createStyleTag/index.ts
function createStyleTag(style, options) {
  invariant(isBrowser());
  const { id, ...rest } = options;
  const styleTag = document.querySelector(`style[#${id}]`);
  if (styleTag)
    return styleTag;
  const styleNode = document.createElement("style");
  const values = Object.entries(rest);
  for (const [k, v] of values) {
    styleNode.setAttribute(k, v);
  }
  styleNode.setAttribute("id", id);
  styleNode.innerHTML = style;
  document.getElementsByTagName("head")[0].appendChild(styleNode);
  return styleNode;
}

exports.createStyleTag = createStyleTag;
