@jsenv/dom 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/jsenv_dom.js +14 -3
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -415,6 +415,10 @@ const parseCSSColor = (color, element) => {
415
415
 
416
416
  // If it's a CSS custom property, resolve it using getComputedStyle
417
417
  if (resolvedColor.includes("var(")) {
418
+ if (!element) {
419
+ // console.warn(`"${resolvedColor}" cannot be resolved without element.`);
420
+ return resolvedColor;
421
+ }
418
422
  const computedStyle = getComputedStyle(element);
419
423
 
420
424
  // Handle var() syntax
@@ -563,11 +567,15 @@ const convertColorToRgba = (color) => {
563
567
  * @param {Array<number>} rgba - [r, g, b, a] values
564
568
  * @returns {string|null} CSS color string or null if invalid input
565
569
  */
566
- const stringifyCSSColor = (rgba) => {
567
- if (!Array.isArray(rgba) || rgba.length < 3) {
570
+ const stringifyCSSColor = (value) => {
571
+ if (typeof value === "string") {
572
+ // can happen for css variables that we can't resolve
573
+ return value;
574
+ }
575
+ if (!Array.isArray(value) || value.length < 3) {
568
576
  return null;
569
577
  }
570
-
578
+ const rgba = value;
571
579
  const [r, g, b, a = 1] = rgba;
572
580
 
573
581
  // Validate RGB values
@@ -2369,6 +2377,9 @@ const mergeTwoStyles = (stylesA, stylesB, context = "js") => {
2369
2377
  const aKeys = Object.keys(stylesA);
2370
2378
  // in case stylesB is a string we first parse it
2371
2379
  stylesB = normalizeStyles(stylesB, context);
2380
+ if (aKeys.length === 0) {
2381
+ return stylesB;
2382
+ }
2372
2383
  const bKeyToVisitSet = new Set(Object.keys(stylesB));
2373
2384
  for (const aKey of aKeys) {
2374
2385
  const bHasKey = bKeyToVisitSet.has(aKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "DOM utilities for writing frontend code",
5
5
  "repository": {
6
6
  "type": "git",