@agencecinq/utils 2.0.0 → 2.0.2
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/.turbo/turbo-build.log +13 -0
- package/dist/environment.d.ts +19 -0
- package/dist/events.d.ts +8 -0
- package/dist/focus-trap.d.ts +4 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +109 -0
- package/dist/keycode.d.ts +17 -0
- package/dist/scroll.d.ts +9 -0
- package/dist/throttle.d.ts +12 -0
- package/package.json +10 -10
- package/src/environment.ts +1 -1
- package/tsconfig.json +16 -0
- package/vite.config.ts +1 -2
- package/CHANGELOG.md +0 -13
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @agencecinq/utils@2.0.1 build /Users/19h47/Sites/agencecinq-shopify/packages/utils
|
|
4
|
+
> vite build
|
|
5
|
+
|
|
6
|
+
[36mvite v7.3.1 [32mbuilding client environment for production...[36m[39m
|
|
7
|
+
[2K[1Gtransforming (1) [2msrc/index.ts[22m[2K[1Gtransforming (3) [2msrc/events.ts[22m[2K[1G[32m✓[39m 7 modules transformed.
|
|
8
|
+
[2K[1Grendering chunks (1)...[2K[1G[32m
|
|
9
|
+
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
10
|
+
[2K[1Gcomputing gzip size (0)...[2K[1Gcomputing gzip size (1)...[2K[1G[2mdist/[22m[36mindex.js [39m[1m[2m3.28 kB[22m[1m[22m[2m │ gzip: 1.52 kB[22m
|
|
11
|
+
[32m[36m[vite:dts][32m Declaration files built in 2669ms.
|
|
12
|
+
[39m
|
|
13
|
+
[32m✓ built in 3.22s[39m
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const html: HTMLElement;
|
|
2
|
+
declare const body: HTMLElement;
|
|
3
|
+
declare const isDebug: boolean;
|
|
4
|
+
declare const scroll: {
|
|
5
|
+
y: number;
|
|
6
|
+
x: number;
|
|
7
|
+
};
|
|
8
|
+
declare const mouse: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
declare const breakpoints: {
|
|
13
|
+
lg: MediaQueryList;
|
|
14
|
+
xl: MediaQueryList;
|
|
15
|
+
'2xl': MediaQueryList;
|
|
16
|
+
'3xl': MediaQueryList;
|
|
17
|
+
};
|
|
18
|
+
declare const production: boolean;
|
|
19
|
+
export { html, body, isDebug, scroll, mouse, breakpoints, production };
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare function getFocusableElements(container: HTMLElement): HTMLElement[];
|
|
2
|
+
declare function addTrapFocus(container: HTMLElement, elementToFocus?: HTMLElement): void;
|
|
3
|
+
declare function removeTrapFocus(elementToFocus?: HTMLElement | null): void;
|
|
4
|
+
export { addTrapFocus, removeTrapFocus, getFocusableElements };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const O = {
|
|
2
|
+
DRAWER_CLOSE: "drawer-close",
|
|
3
|
+
DRAWER_OPEN: "drawer-open",
|
|
4
|
+
DRAWER_TOGGLE: "drawer-toggle",
|
|
5
|
+
CART_UPDATE: "cart-update",
|
|
6
|
+
VARIANT_CHANGE: "variant-change"
|
|
7
|
+
}, f = (e, t) => {
|
|
8
|
+
let n = null, r = null;
|
|
9
|
+
const s = () => {
|
|
10
|
+
r && e(...r), n = null;
|
|
11
|
+
};
|
|
12
|
+
return (...c) => {
|
|
13
|
+
r = c, n || (n = setTimeout(s, t));
|
|
14
|
+
};
|
|
15
|
+
}, l = document.documentElement, { body: d } = document, W = l.hasAttribute("data-debug"), o = {
|
|
16
|
+
y: 0,
|
|
17
|
+
x: 0
|
|
18
|
+
}, a = {
|
|
19
|
+
x: 0,
|
|
20
|
+
y: 0
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener(
|
|
23
|
+
"pointermove",
|
|
24
|
+
f(({ x: e, y: t }) => {
|
|
25
|
+
a.x = e, a.y = t;
|
|
26
|
+
}, 100),
|
|
27
|
+
{ passive: !0 }
|
|
28
|
+
);
|
|
29
|
+
const k = {
|
|
30
|
+
lg: window.matchMedia("(width >= 64rem)"),
|
|
31
|
+
xl: window.matchMedia("(min-width: 1280px)"),
|
|
32
|
+
"2xl": window.matchMedia("(min-width: 1440px)"),
|
|
33
|
+
"3xl": window.matchMedia("(min-width: 1920px)")
|
|
34
|
+
}, C = !0, u = (e, t) => {
|
|
35
|
+
typeof e < "u" && (o.x = e), typeof t < "u" && (o.y = t), window.scrollTo(o.x, o.y);
|
|
36
|
+
};
|
|
37
|
+
function N() {
|
|
38
|
+
const e = l.scrollLeft, t = l.scrollTop, n = d.scrollLeft, r = d.scrollTop;
|
|
39
|
+
o.x = window.scrollX || e || n, o.y = window.scrollY || t || r || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(o.x, o.y);
|
|
40
|
+
}
|
|
41
|
+
function H(e = 0) {
|
|
42
|
+
let t = !0, n = o.y;
|
|
43
|
+
typeof e == "number" ? n = e : typeof e == "boolean" && e === !1 && (t = !1), l.style.removeProperty("overflow"), l.style.removeProperty("height"), l.style.removeProperty("scroll-padding-top"), t && u(o.x, n);
|
|
44
|
+
}
|
|
45
|
+
const i = {};
|
|
46
|
+
function y(e) {
|
|
47
|
+
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
|
|
48
|
+
}
|
|
49
|
+
function m(e) {
|
|
50
|
+
if (!e) return [];
|
|
51
|
+
const t = [
|
|
52
|
+
"summary",
|
|
53
|
+
"a[href]",
|
|
54
|
+
"button:enabled",
|
|
55
|
+
'[tabindex]:not([tabindex^="-"])',
|
|
56
|
+
"input:not([type=hidden]):enabled",
|
|
57
|
+
"select:enabled",
|
|
58
|
+
"textarea:enabled",
|
|
59
|
+
"object",
|
|
60
|
+
"iframe",
|
|
61
|
+
"[contenteditable]"
|
|
62
|
+
].join(",");
|
|
63
|
+
return Array.from(e.querySelectorAll(t)).filter((n) => y(n) && n.getAttribute("tabindex") !== "-1");
|
|
64
|
+
}
|
|
65
|
+
function G(e, t = e) {
|
|
66
|
+
const n = m(e);
|
|
67
|
+
if (n.length === 0) return;
|
|
68
|
+
const r = n[0], s = n[n.length - 1];
|
|
69
|
+
E(), i.keydown = (c) => {
|
|
70
|
+
c.key === "Tab" && (c.shiftKey ? (document.activeElement === r || document.activeElement === e) && (c.preventDefault(), s.focus()) : document.activeElement === s && (c.preventDefault(), r.focus()));
|
|
71
|
+
}, document.addEventListener("keydown", i.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
|
|
72
|
+
}
|
|
73
|
+
function E(e = null) {
|
|
74
|
+
i.keydown && document.removeEventListener("keydown", i.keydown), e && e.focus();
|
|
75
|
+
}
|
|
76
|
+
const p = 8, w = 9, h = 13, b = 16, A = 27, x = 32, g = 33, R = 34, v = 35, P = 36, S = 37, T = 38, L = 39, D = 40, _ = 46, M = {
|
|
77
|
+
BACKSPACE: p,
|
|
78
|
+
TAB: w,
|
|
79
|
+
ENTER: h,
|
|
80
|
+
SHIFT: b,
|
|
81
|
+
ESCAPE: A,
|
|
82
|
+
SPACE: x,
|
|
83
|
+
PAGE_UP: g,
|
|
84
|
+
PAGE_DOWN: R,
|
|
85
|
+
END: v,
|
|
86
|
+
HOME: P,
|
|
87
|
+
ARROW_LEFT: S,
|
|
88
|
+
ARROW_UP: T,
|
|
89
|
+
ARROW_RIGHT: L,
|
|
90
|
+
ARROW_DOWN: D,
|
|
91
|
+
DELETE: _
|
|
92
|
+
};
|
|
93
|
+
export {
|
|
94
|
+
O as EVENTS,
|
|
95
|
+
G as addTrapFocus,
|
|
96
|
+
d as body,
|
|
97
|
+
k as breakpoints,
|
|
98
|
+
N as disableScroll,
|
|
99
|
+
H as enableScroll,
|
|
100
|
+
m as getFocusableElements,
|
|
101
|
+
l as html,
|
|
102
|
+
W as isDebug,
|
|
103
|
+
M as keycode,
|
|
104
|
+
a as mouse,
|
|
105
|
+
C as production,
|
|
106
|
+
E as removeTrapFocus,
|
|
107
|
+
o as scroll,
|
|
108
|
+
f as throttle
|
|
109
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const keycode: {
|
|
2
|
+
BACKSPACE: number;
|
|
3
|
+
TAB: number;
|
|
4
|
+
ENTER: number;
|
|
5
|
+
SHIFT: number;
|
|
6
|
+
ESCAPE: number;
|
|
7
|
+
SPACE: number;
|
|
8
|
+
PAGE_UP: number;
|
|
9
|
+
PAGE_DOWN: number;
|
|
10
|
+
END: number;
|
|
11
|
+
HOME: number;
|
|
12
|
+
ARROW_LEFT: number;
|
|
13
|
+
ARROW_UP: number;
|
|
14
|
+
ARROW_RIGHT: number;
|
|
15
|
+
ARROW_DOWN: number;
|
|
16
|
+
DELETE: number;
|
|
17
|
+
};
|
package/dist/scroll.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* disableScroll
|
|
3
|
+
*
|
|
4
|
+
* Lock scroll position, but retain settings for later
|
|
5
|
+
*
|
|
6
|
+
* @see http://stackoverflow.com/a/3656618
|
|
7
|
+
*/
|
|
8
|
+
export declare function disableScroll(): void;
|
|
9
|
+
export declare function enableScroll(position?: number | boolean | undefined): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ThrottleFunction {
|
|
2
|
+
(func: (...args: any[]) => void, wait: number): (...args: any[]) => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds.
|
|
6
|
+
*
|
|
7
|
+
* @param func - The function to throttle.
|
|
8
|
+
* @param wait - The number of milliseconds to wait before allowing `func` to be called again.
|
|
9
|
+
* @returns A new throttled function.
|
|
10
|
+
*/
|
|
11
|
+
export declare const throttle: ThrottleFunction;
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agencecinq/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"module": "./dist/index.js",
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
18
17
|
}
|
|
19
18
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"dev": "vite",
|
|
22
|
-
"build": "vite build"
|
|
23
|
-
},
|
|
24
19
|
"devDependencies": {
|
|
25
|
-
"
|
|
26
|
-
"vite
|
|
20
|
+
"typescript": "^5.9.3",
|
|
21
|
+
"vite": "^7.3.1",
|
|
22
|
+
"vite-plugin-dts": "^4.5.4"
|
|
27
23
|
},
|
|
28
24
|
"publishConfig": {
|
|
29
25
|
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "vite",
|
|
29
|
+
"build": "vite build"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/environment.ts
CHANGED
|
@@ -30,6 +30,6 @@ const breakpoints = {
|
|
|
30
30
|
'3xl': window.matchMedia('(min-width: 1920px)'),
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const production =
|
|
33
|
+
const production = import.meta.env.PROD;
|
|
34
34
|
|
|
35
35
|
export { html, body, isDebug, scroll, mouse, breakpoints, production };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"baseUrl": ".",
|
|
10
|
+
"paths": {
|
|
11
|
+
"@agencecinq/utils": ["./src/index.ts"]
|
|
12
|
+
},
|
|
13
|
+
"types": ["vite/client"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"]
|
|
16
|
+
}
|
package/vite.config.ts
CHANGED