@zag-js/focus-visible 0.10.2 → 0.10.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  type Modality = "keyboard" | "pointer" | "virtual";
2
2
  type FocusVisibleCallback = (isFocusVisible: boolean) => void;
3
- declare function trackFocusVisible(fn: FocusVisibleCallback): () => void;
4
- declare function trackInteractionModality(fn: (value: Modality | null) => void): () => void;
5
- declare function setInteractionModality(value: Modality): void;
6
- declare function getInteractionModality(): Modality | null;
7
-
8
- export { getInteractionModality, setInteractionModality, trackFocusVisible, trackInteractionModality };
3
+ export declare function trackFocusVisible(fn: FocusVisibleCallback): () => void;
4
+ export declare function trackInteractionModality(fn: (value: Modality | null) => void): () => void;
5
+ export declare function setInteractionModality(value: Modality): void;
6
+ export declare function getInteractionModality(): Modality | null;
7
+ export {};
package/dist/index.js CHANGED
@@ -1,40 +1,18 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
19
4
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- getInteractionModality: () => getInteractionModality,
24
- setInteractionModality: () => setInteractionModality,
25
- trackFocusVisible: () => trackFocusVisible,
26
- trackInteractionModality: () => trackInteractionModality
27
- });
28
- module.exports = __toCommonJS(src_exports);
29
- var hasSetup = false;
30
- var modality = null;
31
- var hasEventBeforeFocus = false;
32
- var hasBlurredWindowRecently = false;
33
- var handlers = /* @__PURE__ */ new Set();
5
+ const domQuery = require('@zag-js/dom-query');
6
+
7
+ let hasSetup = false;
8
+ let modality = null;
9
+ let hasEventBeforeFocus = false;
10
+ let hasBlurredWindowRecently = false;
11
+ const handlers = /* @__PURE__ */ new Set();
34
12
  function trigger(modality2, event) {
35
13
  handlers.forEach((handler) => handler(modality2, event));
36
14
  }
37
- var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
15
+ const isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
38
16
  function isValidKey(e) {
39
17
  return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
40
18
  }
@@ -90,7 +68,7 @@ function isFocusVisible() {
90
68
  return modality !== "pointer";
91
69
  }
92
70
  function setupGlobalFocusEvents() {
93
- if (typeof window === "undefined" || hasSetup) {
71
+ if (!domQuery.isDom() || hasSetup) {
94
72
  return;
95
73
  }
96
74
  const { focus } = HTMLElement.prototype;
@@ -139,10 +117,8 @@ function setInteractionModality(value) {
139
117
  function getInteractionModality() {
140
118
  return modality;
141
119
  }
142
- // Annotate the CommonJS export names for ESM import in node:
143
- 0 && (module.exports = {
144
- getInteractionModality,
145
- setInteractionModality,
146
- trackFocusVisible,
147
- trackInteractionModality
148
- });
120
+
121
+ exports.getInteractionModality = getInteractionModality;
122
+ exports.setInteractionModality = setInteractionModality;
123
+ exports.trackFocusVisible = trackFocusVisible;
124
+ exports.trackInteractionModality = trackInteractionModality;
package/dist/index.mjs CHANGED
@@ -1,13 +1,14 @@
1
- // src/index.ts
2
- var hasSetup = false;
3
- var modality = null;
4
- var hasEventBeforeFocus = false;
5
- var hasBlurredWindowRecently = false;
6
- var handlers = /* @__PURE__ */ new Set();
1
+ import { isDom } from '@zag-js/dom-query';
2
+
3
+ let hasSetup = false;
4
+ let modality = null;
5
+ let hasEventBeforeFocus = false;
6
+ let hasBlurredWindowRecently = false;
7
+ const handlers = /* @__PURE__ */ new Set();
7
8
  function trigger(modality2, event) {
8
9
  handlers.forEach((handler) => handler(modality2, event));
9
10
  }
10
- var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
11
+ const isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
11
12
  function isValidKey(e) {
12
13
  return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
13
14
  }
@@ -63,7 +64,7 @@ function isFocusVisible() {
63
64
  return modality !== "pointer";
64
65
  }
65
66
  function setupGlobalFocusEvents() {
66
- if (typeof window === "undefined" || hasSetup) {
67
+ if (!isDom() || hasSetup) {
67
68
  return;
68
69
  }
69
70
  const { focus } = HTMLElement.prototype;
@@ -112,9 +113,5 @@ function setInteractionModality(value) {
112
113
  function getInteractionModality() {
113
114
  return modality;
114
115
  }
115
- export {
116
- getInteractionModality,
117
- setInteractionModality,
118
- trackFocusVisible,
119
- trackInteractionModality
120
- };
116
+
117
+ export { getInteractionModality, setInteractionModality, trackFocusVisible, trackInteractionModality };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/focus-visible",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "Focus visible polyfill utility based on WICG",
5
5
  "keywords": [
6
6
  "js",
@@ -25,6 +25,9 @@
25
25
  },
26
26
  "clean-package": "../../../clean-package.config.json",
27
27
  "main": "dist/index.js",
28
+ "dependencies": {
29
+ "@zag-js/dom-query": "0.10.4"
30
+ },
28
31
  "devDependencies": {
29
32
  "clean-package": "2.2.0"
30
33
  },
@@ -39,9 +42,7 @@
39
42
  "./package.json": "./package.json"
40
43
  },
41
44
  "scripts": {
42
- "build-fast": "tsup src",
43
- "start": "pnpm build --watch",
44
- "build": "tsup src --dts",
45
+ "build": "vite build -c ../../../vite.config.ts",
45
46
  "test": "jest --config ../../../jest.config.js --rootDir tests",
46
47
  "lint": "eslint src --ext .ts,.tsx",
47
48
  "test-ci": "pnpm test --ci --runInBand -u",
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { isDom } from "@zag-js/dom-query"
2
+
1
3
  type Modality = "keyboard" | "pointer" | "virtual"
2
4
  type HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent
3
5
  type Handler = (modality: Modality, e: HandlerEvent | null) => void
@@ -96,7 +98,7 @@ function isFocusVisible() {
96
98
  }
97
99
 
98
100
  function setupGlobalFocusEvents() {
99
- if (typeof window === "undefined" || hasSetup) {
101
+ if (!isDom() || hasSetup) {
100
102
  return
101
103
  }
102
104