UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.8 kB
{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["\r\nimport { getDocument } from \"ssr-window\";\r\n\r\nexport type TRemoveCSSVarArgs = Parameters<typeof removeCSSVar>;\r\n\r\nexport type TRemoveCSSVarReturn = ReturnType<typeof removeCSSVar>;\r\n\r\n/**\r\n * Removes CSS3 variable from specific DOM node\r\n * @param el{HTMLElement|Node|Element|Document=} DOM element\r\n * @param variable{String} variable name\r\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties\r\n * @throws {TypeError} removeCSSVar: el must be an HTMLElement\r\n * @throws {TypeError} removeCSSVar: variable must be a non-empty string\r\n * @example\r\n * // How to remove CSS variable from div?\r\n * // <div id=\"myBlock\" style=\"--myVar: 10;\"></div>\r\n * const block = document.getElementById(\"myBlock\");\r\n * removeCSSVar(block, \"myVar\");\r\n * // <div id=\"myBlock\" style=\"\"></div>\r\n */\r\nexport const removeCSSVar = (el: HTMLElement = getDocument().documentElement, variable: string) => {\r\n if (!el || typeof (el as any).style !== \"object\") {\r\n throw new TypeError(\"removeCSSVar: el must be an HTMLElement\");\r\n }\r\n if (typeof variable !== \"string\" || variable.length === 0) {\r\n throw new TypeError(\"removeCSSVar: variable must be a non-empty string\");\r\n }\r\n el.style.removeProperty(variable.startsWith(\"--\") ? variable : `--${variable}`);\r\n};\r\n"],"names":["removeCSSVar","el","getDocument","documentElement","variable","style","TypeError","length","removeProperty","startsWith"],"mappings":";;;;;;;;;;;;;;GAqBO,MAAMA,aAAeA,CAACC,GAAkBC,UAAAA,cAAcC,gBAAiBC,YAC5E,IAAKH,WAAcA,GAAWI,QAAU,SACtC,MAAM,IAAIC,UAAU,2CAEtB,UAAWF,WAAa,UAAYA,SAASG,SAAW,EACtD,MAAM,IAAID,UAAU,qDAEtBL,GAAGI,MAAMG,eAAeJ,SAASK,WAAW,MAAQL,SAAW,KAAKA"}