@jsenv/dom 0.8.6 → 0.8.7

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 +72 -27
  2. package/package.json +1 -1
package/dist/jsenv_dom.js CHANGED
@@ -422,6 +422,40 @@ const parseCSSColor = (color, element) => {
422
422
  return parseCSSColor(resolvedColor, element);
423
423
  }
424
424
 
425
+ if (color.startsWith("color-mix(")) {
426
+ return color;
427
+ }
428
+
429
+ // Pass through CSS functions that we don't want to resolve
430
+ if (
431
+ color.includes("calc(") ||
432
+ color.includes("min(") ||
433
+ color.includes("max(") ||
434
+ color.includes("clamp(") ||
435
+ color.includes("env(") ||
436
+ color.includes("attr(")
437
+ ) {
438
+ return color;
439
+ }
440
+
441
+ // Pass through CSS color functions we don't handle
442
+ if (
443
+ color.startsWith("color(") ||
444
+ color.startsWith("lch(") ||
445
+ color.startsWith("oklch(") ||
446
+ color.startsWith("lab(") ||
447
+ color.startsWith("oklab(") ||
448
+ color.startsWith("hwb(") ||
449
+ color.includes("color-contrast(")
450
+ ) {
451
+ return color;
452
+ }
453
+
454
+ // Pass through relative color syntax (CSS Color Module Level 5)
455
+ if (color.includes(" from ")) {
456
+ return color;
457
+ }
458
+
425
459
  // If it's a CSS custom property, resolve it using getComputedStyle
426
460
  if (resolvedColor.includes("var(")) {
427
461
  if (!element) {
@@ -3671,26 +3705,29 @@ const createPreviousNodeIterator = (fromNode, rootNode, skipRoot = null) => {
3671
3705
  };
3672
3706
  };
3673
3707
 
3674
- const activeElementSignal = signal(document.activeElement);
3675
-
3676
- document.addEventListener(
3677
- "focus",
3678
- () => {
3679
- activeElementSignal.value = document.activeElement;
3680
- },
3681
- { capture: true },
3708
+ const activeElementSignal = signal(
3709
+ typeof document === "object" ? document.activeElement : undefined,
3682
3710
  );
3683
- // When clicking on document there is no "focus" event dispatched on the document
3684
- // We can detect that with "blur" event when relatedTarget is null
3685
- document.addEventListener(
3686
- "blur",
3687
- (e) => {
3688
- if (!e.relatedTarget) {
3711
+ if (typeof document === "object") {
3712
+ document.addEventListener(
3713
+ "focus",
3714
+ () => {
3689
3715
  activeElementSignal.value = document.activeElement;
3690
- }
3691
- },
3692
- { capture: true },
3693
- );
3716
+ },
3717
+ { capture: true },
3718
+ );
3719
+ // When clicking on document there is no "focus" event dispatched on the document
3720
+ // We can detect that with "blur" event when relatedTarget is null
3721
+ document.addEventListener(
3722
+ "blur",
3723
+ (e) => {
3724
+ if (!e.relatedTarget) {
3725
+ activeElementSignal.value = document.activeElement;
3726
+ }
3727
+ },
3728
+ { capture: true },
3729
+ );
3730
+ }
3694
3731
 
3695
3732
  const useActiveElement = () => {
3696
3733
  return activeElementSignal.value;
@@ -5059,7 +5096,8 @@ const bodyIsScrollable = (body) => {
5059
5096
  // https://developer.mozilla.org/en-US/docs/Glossary/Scroll_container
5060
5097
 
5061
5098
 
5062
- const { documentElement: documentElement$2 } = document;
5099
+ const { documentElement: documentElement$2 } =
5100
+ typeof document === "object" ? document : { documentElement: null };
5063
5101
 
5064
5102
  const getScrollContainer = (arg, { includeHidden } = {}) => {
5065
5103
  if (typeof arg !== "object" || arg.nodeType !== 1) {
@@ -5300,7 +5338,8 @@ const getBorderSizes = (element) => {
5300
5338
  */
5301
5339
 
5302
5340
 
5303
- const { documentElement: documentElement$1 } = document;
5341
+ const { documentElement: documentElement$1 } =
5342
+ typeof document === "object" ? document : { documentElement: null };
5304
5343
 
5305
5344
  /**
5306
5345
  * Get element rectangle relative to its scroll container
@@ -6163,7 +6202,9 @@ const isOverlayOf = (element, potentialTarget) => {
6163
6202
  return false;
6164
6203
  };
6165
6204
 
6166
- const { documentElement } = document;
6205
+ const { documentElement } =
6206
+ typeof document === "object" ? document : { documentElement: null };
6207
+
6167
6208
  const createGetScrollOffsets = (
6168
6209
  scrollContainer,
6169
6210
  referenceScrollContainer,
@@ -9665,7 +9706,9 @@ const startTimeline = () => {
9665
9706
  backgroundUpdateLoop.start();
9666
9707
  animationUpdateLoop.start();
9667
9708
  };
9668
- startTimeline();
9709
+ if (typeof document === "object") {
9710
+ startTimeline();
9711
+ }
9669
9712
 
9670
9713
  // Default lifecycle methods that do nothing
9671
9714
  const LIFECYCLE_DEFAULT = {
@@ -9685,11 +9728,13 @@ const onTransitionPausedByBreakpoint = (transition) => {
9685
9728
  const cleanupTransitionPausedByBreakpoint = (transition) => {
9686
9729
  transitionPausedByBreakpointWeakSet.delete(transition);
9687
9730
  };
9688
- window.resumeTransitions = () => {
9689
- for (const transition of transitionPausedByBreakpointWeakSet) {
9690
- transition.play();
9691
- }
9692
- };
9731
+ if (typeof window !== "undefined") {
9732
+ window.resumeTransitions = () => {
9733
+ for (const transition of transitionPausedByBreakpointWeakSet) {
9734
+ transition.play();
9735
+ }
9736
+ };
9737
+ }
9693
9738
 
9694
9739
  const combineTwoLifecycle = (lifecycleA, lifecycleB) => {
9695
9740
  if (!lifecycleA && !lifecycleB) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/dom",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "DOM utilities for writing frontend code",
5
5
  "repository": {
6
6
  "type": "git",