@jsenv/dom 0.5.1 → 0.5.3

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.
package/dist/jsenv_dom.js CHANGED
@@ -418,20 +418,15 @@ const normalizeNumber = (value, context, unit, propertyName) => {
418
418
  return value;
419
419
  }
420
420
  if (typeof value === "string") {
421
- if (value === "auto") {
422
- return "auto";
423
- }
424
- if (value === "none") {
425
- return "none";
426
- }
427
- const numericValue = parseFloat(value);
428
- if (isNaN(numericValue)) {
429
- console.warn(
430
- `"${propertyName}": ${value} cannot be converted to number, returning value as-is.`,
431
- );
432
- return value;
421
+ // For js context, only convert px values to numbers
422
+ if (unit === "px" && value.endsWith("px")) {
423
+ const numericValue = parseFloat(value);
424
+ if (!isNaN(numericValue)) {
425
+ return numericValue;
426
+ }
433
427
  }
434
- return numericValue;
428
+ // Keep all other strings as-is (including %, em, rem, auto, none, etc.)
429
+ return value;
435
430
  }
436
431
  return value;
437
432
  };
@@ -668,6 +663,8 @@ const mergeStyles = (stylesA, stylesB, context = "js") => {
668
663
  }
669
664
  const result = {};
670
665
  const aKeys = Object.keys(stylesA);
666
+ // in case stylesB is a string we first parse it
667
+ stylesB = normalizeStyles(stylesB, context);
671
668
  const bKeyToVisitSet = new Set(Object.keys(stylesB));
672
669
  for (const aKey of aKeys) {
673
670
  const bHasKey = bKeyToVisitSet.has(aKey);
@@ -679,7 +676,7 @@ const mergeStyles = (stylesA, stylesB, context = "js") => {
679
676
  }
680
677
  }
681
678
  for (const bKey of bKeyToVisitSet) {
682
- result[bKey] = normalizeStyle(stylesB[bKey], bKey, context);
679
+ result[bKey] = stylesB[bKey];
683
680
  }
684
681
  return result;
685
682
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "DOM utilities for writing frontend code",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,6 +15,8 @@ export const mergeStyles = (stylesA, stylesB, context = "js") => {
15
15
  }
16
16
  const result = {};
17
17
  const aKeys = Object.keys(stylesA);
18
+ // in case stylesB is a string we first parse it
19
+ stylesB = normalizeStyles(stylesB, context);
18
20
  const bKeyToVisitSet = new Set(Object.keys(stylesB));
19
21
  for (const aKey of aKeys) {
20
22
  const bHasKey = bKeyToVisitSet.has(aKey);
@@ -26,7 +28,7 @@ export const mergeStyles = (stylesA, stylesB, context = "js") => {
26
28
  }
27
29
  }
28
30
  for (const bKey of bKeyToVisitSet) {
29
- result[bKey] = normalizeStyle(stylesB[bKey], bKey, context);
31
+ result[bKey] = stylesB[bKey];
30
32
  }
31
33
  return result;
32
34
  };
@@ -136,20 +136,15 @@ const normalizeNumber = (value, context, unit, propertyName) => {
136
136
  return value;
137
137
  }
138
138
  if (typeof value === "string") {
139
- if (value === "auto") {
140
- return "auto";
141
- }
142
- if (value === "none") {
143
- return "none";
144
- }
145
- const numericValue = parseFloat(value);
146
- if (isNaN(numericValue)) {
147
- console.warn(
148
- `"${propertyName}": ${value} cannot be converted to number, returning value as-is.`,
149
- );
150
- return value;
139
+ // For js context, only convert px values to numbers
140
+ if (unit === "px" && value.endsWith("px")) {
141
+ const numericValue = parseFloat(value);
142
+ if (!isNaN(numericValue)) {
143
+ return numericValue;
144
+ }
151
145
  }
152
- return numericValue;
146
+ // Keep all other strings as-is (including %, em, rem, auto, none, etc.)
147
+ return value;
153
148
  }
154
149
  return value;
155
150
  };