@jsenv/dom 0.9.3 → 0.9.5

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 +42 -7
  2. package/package.json +7 -7
package/dist/jsenv_dom.js CHANGED
@@ -2227,6 +2227,9 @@ const normalizeStyle = (
2227
2227
  if (propertyName === "lineHeight") {
2228
2228
  if (context === "js") {
2229
2229
  if (typeof value === "string") {
2230
+ if (isCSSFunction(value)) {
2231
+ return value;
2232
+ }
2230
2233
  const unit = getUnit(value);
2231
2234
  if (unit === "px") {
2232
2235
  const float = parseFloat(value);
@@ -2271,6 +2274,9 @@ const normalizeStyle = (
2271
2274
  }
2272
2275
 
2273
2276
  if (colorPropertySet.has(propertyName)) {
2277
+ if (typeof value === "string" && isCSSFunction(value)) {
2278
+ return value;
2279
+ }
2274
2280
  const rgba = parseCSSColor(value, element);
2275
2281
  if (context === "js") {
2276
2282
  return rgba;
@@ -2287,8 +2293,15 @@ const stringifyStyle = (value, propertyName, element) => {
2287
2293
  return normalizeStyle(value, propertyName, "css", element);
2288
2294
  };
2289
2295
 
2296
+ const isCSSFunction = (value) => {
2297
+ return /^[a-z-]+\(/.test(value);
2298
+ };
2290
2299
  const normalizeNumber = (value, { unit, propertyName, preferedType }) => {
2291
2300
  if (typeof value === "string") {
2301
+ // CSS variables and CSS functions like calc() must be passed through as-is
2302
+ if (isCSSFunction(value)) {
2303
+ return value;
2304
+ }
2292
2305
  // Keep strings as-is (including %, em, rem, auto, none, etc.)
2293
2306
  if (preferedType === "string") {
2294
2307
  if (unit && isUnitless(value) && !unitlessKeywordSet.has(value)) {
@@ -3982,16 +3995,38 @@ const findFocusable = (element) => {
3982
3995
  return focusableDescendant;
3983
3996
  };
3984
3997
 
3998
+ // Input types where ArrowUp/Down natively change the value — don't intercept them
3999
+ const INPUT_TYPES_WITH_ARROW_MEANING = new Set([
4000
+ "number",
4001
+ "range",
4002
+ "date",
4003
+ "time",
4004
+ "datetime-local",
4005
+ "month",
4006
+ "week",
4007
+ ]);
4008
+ const INPUT_ALLOWED_KEYS = new Set(["Home", "End", "Escape", "Enter"]);
4009
+ const INPUT_ARROW_KEYS = new Set(["ArrowDown", "ArrowUp"]);
4010
+ const TEXTAREA_ALLOWED_KEYS = new Set(["Escape"]);
4011
+
3985
4012
  const canInterceptKeys = (event) => {
3986
4013
  const target = event.target;
3987
- // Don't handle shortcuts when user is typing
4014
+ // Allow specific keys on input/textarea/contenteditable elements
4015
+ if (target.tagName === "INPUT") {
4016
+ if (INPUT_ALLOWED_KEYS.has(event.key)) {
4017
+ return true;
4018
+ }
4019
+ if (INPUT_ARROW_KEYS.has(event.key)) {
4020
+ return !INPUT_TYPES_WITH_ARROW_MEANING.has(target.type);
4021
+ }
4022
+ return false;
4023
+ }
3988
4024
  if (
3989
- target.tagName === "INPUT" ||
3990
4025
  target.tagName === "TEXTAREA" ||
3991
4026
  target.contentEditable === "true" ||
3992
4027
  target.isContentEditable
3993
4028
  ) {
3994
- return false;
4029
+ return TEXTAREA_ALLOWED_KEYS.has(event.key);
3995
4030
  }
3996
4031
  // Don't handle shortcuts when select dropdown is open
3997
4032
  if (target.tagName === "SELECT") {
@@ -7052,7 +7087,7 @@ import.meta.css = [/* css */`
7052
7087
  inset: 0;
7053
7088
  user-select: none;
7054
7089
  }
7055
- `, "/src/interaction/drag/drag_gesture.js"];
7090
+ `, "@jsenv/dom/src/interaction/drag/drag_gesture.js"];
7056
7091
 
7057
7092
  installImportMetaCssBuild(import.meta);const setupConstraintFeedbackLine = () => {
7058
7093
  const constraintFeedbackLine = createConstraintFeedbackLine();
@@ -7141,7 +7176,7 @@ import.meta.css = [/* css */`
7141
7176
  .navi_constraint_feedback_line[data-visible] {
7142
7177
  visibility: visible;
7143
7178
  }
7144
- `, "/src/interaction/drag/constraint_feedback_line.js"];
7179
+ `, "@jsenv/dom/src/interaction/drag/constraint_feedback_line.js"];
7145
7180
 
7146
7181
  installImportMetaCssBuild(import.meta);// Keep visual markers (debug markers, obstacle markers, constraint feedback line) in DOM after drag ends
7147
7182
  const MARKER_SIZE = 12;
@@ -7723,7 +7758,7 @@ import.meta.css = [/* css */`
7723
7758
  border-radius: 3px;
7724
7759
  pointer-events: none;
7725
7760
  }
7726
- `, "/src/interaction/drag/drag_debug_markers.js"];
7761
+ `, "@jsenv/dom/src/interaction/drag/drag_debug_markers.js"];
7727
7762
 
7728
7763
  const initDragConstraints = (
7729
7764
  dragGesture,
@@ -8916,7 +8951,7 @@ import.meta.css = [/* css */`
8916
8951
  height: auto !important;
8917
8952
  opacity: 0 !important;
8918
8953
  }
8919
- `, "/src/position/position_sticky.js"];
8954
+ `, "@jsenv/dom/src/position/position_sticky.js"];
8920
8955
  const initPositionSticky = element => {
8921
8956
  const computedStyle = getComputedStyle(element);
8922
8957
  const topCssValue = computedStyle.top;
package/package.json CHANGED
@@ -1,21 +1,18 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
+ "type": "module",
4
5
  "description": "DOM utilities for writing frontend code",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/jsenv/core",
8
9
  "directory": "packages/frontend/dom"
9
10
  },
10
- "license": "MIT",
11
11
  "author": {
12
12
  "name": "dmail",
13
13
  "email": "dmaillard06@gmail.com"
14
14
  },
15
- "sideEffects": [
16
- "./dist/jsenv_dom.js"
17
- ],
18
- "type": "module",
15
+ "license": "MIT",
19
16
  "exports": {
20
17
  ".": {
21
18
  "node": {
@@ -47,5 +44,8 @@
47
44
  },
48
45
  "publishConfig": {
49
46
  "access": "public"
50
- }
47
+ },
48
+ "sideEffects": [
49
+ "./dist/jsenv_dom.js"
50
+ ]
51
51
  }