{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["import { getDocument } from \"ssr-window\";\r\n\r\nexport type TSetCSSVarArgs = Parameters<typeof setCSSVar>;\r\n\r\nexport type TSetCSSVarReturn = ReturnType<typeof setCSSVar>;\r\n\r\n/**\r\n * Sets CSS3 variable to specific DOM node\r\n * @param el{HTMLElement=} DOM element\r\n * @param variable{String} variable name\r\n * @param value{String|Number|Boolean=} variable value\r\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties\r\n * @returns {void}\r\n * @throws {TypeError} setCSSVar: el must be an HTMLElement\r\n * @throws {TypeError} setCSSVar: variable must be a non-empty string\r\n * @throws {TypeError} setCSSVar: value must be a string|number|boolean\r\n * @example\r\n * // How to set CSS variable to div?\r\n * // <div id=\"myBlock\"></div>\r\n * const block = document.getElementById(\"myBlock\");\r\n * setCSSVar(block, \"myVar\", 10);\r\n * // <div id=\"myBlock\" style=\"--myVar: 10\"></div>\r\n */\r\nexport const setCSSVar = (el: HTMLElement = getDocument().documentElement, variable: string, value: string | number | boolean = \"\"): void => {\r\n  if (!el || typeof (el as any).style !== \"object\") {\r\n    throw new TypeError(\"setCSSVar: el must be an HTMLElement\");\r\n  }\r\n  if (typeof variable !== \"string\" || variable.length === 0) {\r\n    throw new TypeError(\"setCSSVar: variable must be a non-empty string\");\r\n  }\r\n  if (typeof value !== \"string\" && typeof value !== \"number\" && typeof value !== \"boolean\") {\r\n    throw new TypeError(\"setCSSVar: value must be a string|number|boolean\");\r\n  }\r\n  el.style.setProperty(variable.startsWith(\"--\") ? variable : `--${variable}`, value + \"\");\r\n};\r\n"],"names":["setCSSVar","el","getDocument","documentElement","variable","value","style","TypeError","length","setProperty","startsWith"],"mappings":";;;;;;;;;;;;;;;;;SAuBaA,UAAYA,CAACC,GAAkBC,cAAcC,gBAAiBC,SAAkBC,MAAmC,MAC9H,IAAKJ,WAAcA,GAAWK,QAAU,SACtC,MAAM,IAAIC,UAAU,wCAEtB,UAAWH,WAAa,UAAYA,SAASI,SAAW,EACtD,MAAM,IAAID,UAAU,kDAEtB,UAAWF,QAAU,iBAAmBA,QAAU,iBAAmBA,QAAU,UAC7E,MAAM,IAAIE,UAAU,oDAEtBN,GAAGK,MAAMG,YAAYL,SAASM,WAAW,MAAQN,SAAW,KAAKA,WAAYC,MAAQ"}