@jsenv/dom 0.7.1 → 0.7.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 +70 -3
- package/package.json +1 -1
package/dist/jsenv_dom.js
CHANGED
|
@@ -463,6 +463,61 @@ const unitlessProperties = [
|
|
|
463
463
|
"scaleZ",
|
|
464
464
|
];
|
|
465
465
|
|
|
466
|
+
// Well-known CSS units and keywords that indicate a value already has proper formatting
|
|
467
|
+
const cssSizeUnitSet = new Set([
|
|
468
|
+
"px",
|
|
469
|
+
"em",
|
|
470
|
+
"rem",
|
|
471
|
+
"ex",
|
|
472
|
+
"ch",
|
|
473
|
+
"vw",
|
|
474
|
+
"vh",
|
|
475
|
+
"vmin",
|
|
476
|
+
"vmax",
|
|
477
|
+
"cm",
|
|
478
|
+
"mm",
|
|
479
|
+
"in",
|
|
480
|
+
"pt",
|
|
481
|
+
"pc",
|
|
482
|
+
]);
|
|
483
|
+
const cssUnitSet = new Set([
|
|
484
|
+
...cssSizeUnitSet,
|
|
485
|
+
"%",
|
|
486
|
+
// Angle units
|
|
487
|
+
"deg",
|
|
488
|
+
"rad",
|
|
489
|
+
"grad",
|
|
490
|
+
"turn",
|
|
491
|
+
// Time units
|
|
492
|
+
"s",
|
|
493
|
+
"ms",
|
|
494
|
+
// Frequency units
|
|
495
|
+
"Hz",
|
|
496
|
+
"kHz",
|
|
497
|
+
]);
|
|
498
|
+
const cssKeywordSet = new Set([
|
|
499
|
+
// Keywords that shouldn't get units
|
|
500
|
+
"auto",
|
|
501
|
+
"none",
|
|
502
|
+
"inherit",
|
|
503
|
+
"initial",
|
|
504
|
+
"unset",
|
|
505
|
+
"revert",
|
|
506
|
+
]);
|
|
507
|
+
|
|
508
|
+
// Check if value already has a unit or is a keyword
|
|
509
|
+
const hasUnit = (value) => {
|
|
510
|
+
for (const cssUnit of cssUnitSet) {
|
|
511
|
+
if (value.endsWith(cssUnit)) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
};
|
|
517
|
+
const isKeyword = (value) => {
|
|
518
|
+
return cssKeywordSet.has(value);
|
|
519
|
+
};
|
|
520
|
+
|
|
466
521
|
// Normalize a single style value
|
|
467
522
|
const normalizeStyle = (value, propertyName, context = "js") => {
|
|
468
523
|
if (propertyName === "transform") {
|
|
@@ -544,6 +599,9 @@ const normalizeNumber = (value, { unit, propertyName, preferedType }) => {
|
|
|
544
599
|
if (typeof value === "string") {
|
|
545
600
|
// Keep strings as-is (including %, em, rem, auto, none, etc.)
|
|
546
601
|
if (preferedType === "string") {
|
|
602
|
+
if (unit && !hasUnit(value) && !isKeyword(value)) {
|
|
603
|
+
return `${value}${unit}`;
|
|
604
|
+
}
|
|
547
605
|
return value;
|
|
548
606
|
}
|
|
549
607
|
// convert to number if possible (font-size: "12px" -> fontSize:12, opacity: "0.5" -> opacity: 0.5)
|
|
@@ -570,14 +628,21 @@ const normalizeNumber = (value, { unit, propertyName, preferedType }) => {
|
|
|
570
628
|
};
|
|
571
629
|
|
|
572
630
|
// Normalize styles for DOM application
|
|
573
|
-
const normalizeStyles = (styles, context = "js") => {
|
|
631
|
+
const normalizeStyles = (styles, context = "js", mutate = false) => {
|
|
574
632
|
if (!styles) {
|
|
575
|
-
return {};
|
|
633
|
+
return mutate ? styles : {};
|
|
576
634
|
}
|
|
577
635
|
if (typeof styles === "string") {
|
|
578
636
|
styles = parseStyleString(styles);
|
|
579
637
|
return styles;
|
|
580
638
|
}
|
|
639
|
+
if (mutate) {
|
|
640
|
+
for (const key of Object.keys(styles)) {
|
|
641
|
+
const value = styles[key];
|
|
642
|
+
styles[key] = normalizeStyle(value, key, context);
|
|
643
|
+
}
|
|
644
|
+
return styles;
|
|
645
|
+
}
|
|
581
646
|
const normalized = {};
|
|
582
647
|
for (const key of Object.keys(styles)) {
|
|
583
648
|
const value = styles[key];
|
|
@@ -10285,6 +10350,8 @@ import.meta.css = /* css */ `
|
|
|
10285
10350
|
flex-direction: inherit;
|
|
10286
10351
|
align-items: inherit;
|
|
10287
10352
|
justify-content: inherit;
|
|
10353
|
+
border-radius: inherit;
|
|
10354
|
+
cursor: inherit;
|
|
10288
10355
|
}
|
|
10289
10356
|
|
|
10290
10357
|
.ui_transition_measure_wrapper[data-transition-translate-x] {
|
|
@@ -11718,4 +11785,4 @@ const notifyTransitionOverflow = (element, transitionId) => {
|
|
|
11718
11785
|
};
|
|
11719
11786
|
};
|
|
11720
11787
|
|
|
11721
|
-
export { EASING, activeElementSignal, addActiveElementEffect, addAttributeEffect, addWillChange, allowWheelThrough, appendStyles, canInterceptKeys, captureScrollState, createDragGestureController, createDragToMoveGestureController, createHeightTransition, createIterableWeakSet, createOpacityTransition, createPubSub, createStyleController, createTimelineTransition, createTransition, createTranslateXTransition, createValueEffect, createWidthTransition, cubicBezier, dragAfterThreshold, elementIsFocusable, elementIsVisibleForFocus, elementIsVisuallyVisible, findAfter, findAncestor, findBefore, findDescendant, findFocusable, getAvailableHeight, getAvailableWidth, getBorderSizes, getContrastRatio, getDefaultStyles, getDragCoordinates, getDropTargetInfo, getElementSignature, getFirstVisuallyVisibleAncestor, getFocusVisibilityInfo, getHeight, getInnerHeight, getInnerWidth, getMarginSizes, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpacity, getPaddingSizes, getPositionedParent, getPreferedColorScheme, getScrollContainer, getScrollContainerSet, getScrollRelativeRect, getSelfAndAncestorScrolls, getStyle, getTranslateX, getTranslateY, getVisuallyVisibleInfo, getWidth, initFlexDetailsSet, initFocusGroup, initPositionSticky, initUITransition, isScrollable, mergeStyles, normalizeStyles, parseCSSColor, pickLightOrDark, pickPositionRelativeTo, prefersDarkColors, prefersLightColors, preventFocusNav, preventFocusNavViaKeyboard, resolveCSSColor, resolveCSSSize, setAttribute, setAttributes, setStyles, startDragToResizeGesture, stickyAsRelativeCoords, stringifyCSSColor, trapFocusInside, trapScrollInside, useActiveElement, useAvailableHeight, useAvailableWidth, useMaxHeight, useMaxWidth, useResizeStatus, visibleRectEffect };
|
|
11788
|
+
export { EASING, activeElementSignal, addActiveElementEffect, addAttributeEffect, addWillChange, allowWheelThrough, appendStyles, canInterceptKeys, captureScrollState, createDragGestureController, createDragToMoveGestureController, createHeightTransition, createIterableWeakSet, createOpacityTransition, createPubSub, createStyleController, createTimelineTransition, createTransition, createTranslateXTransition, createValueEffect, createWidthTransition, cubicBezier, dragAfterThreshold, elementIsFocusable, elementIsVisibleForFocus, elementIsVisuallyVisible, findAfter, findAncestor, findBefore, findDescendant, findFocusable, getAvailableHeight, getAvailableWidth, getBorderSizes, getContrastRatio, getDefaultStyles, getDragCoordinates, getDropTargetInfo, getElementSignature, getFirstVisuallyVisibleAncestor, getFocusVisibilityInfo, getHeight, getInnerHeight, getInnerWidth, getMarginSizes, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpacity, getPaddingSizes, getPositionedParent, getPreferedColorScheme, getScrollContainer, getScrollContainerSet, getScrollRelativeRect, getSelfAndAncestorScrolls, getStyle, getTranslateX, getTranslateY, getVisuallyVisibleInfo, getWidth, initFlexDetailsSet, initFocusGroup, initPositionSticky, initUITransition, isScrollable, mergeStyles, normalizeStyle, normalizeStyles, parseCSSColor, pickLightOrDark, pickPositionRelativeTo, prefersDarkColors, prefersLightColors, preventFocusNav, preventFocusNavViaKeyboard, resolveCSSColor, resolveCSSSize, setAttribute, setAttributes, setStyles, startDragToResizeGesture, stickyAsRelativeCoords, stringifyCSSColor, trapFocusInside, trapScrollInside, useActiveElement, useAvailableHeight, useAvailableWidth, useMaxHeight, useMaxWidth, useResizeStatus, visibleRectEffect };
|