usemods-nuxt 1.4.2 → 1.4.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/README.md CHANGED
@@ -3,12 +3,13 @@
3
3
  # Use Mods (Nuxt Module)
4
4
  Auto-imported functions and modifiers for zippy Nuxt developers.
5
5
 
6
+ <!-- Badges -->
6
7
  [![npm version][npm-version-src]][npm-version-href]
7
8
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
8
9
  [![License][license-src]][license-href]
9
- [![Nuxt][nuxt-src]][nuxt-href]
10
+ [![CI][ci-src]][ci-href]
11
+ [![CodeQL][codeql-src]][codeql-href]
10
12
 
11
- <!-- Badges -->
12
13
  [npm-version-src]: https://img.shields.io/npm/v/usemods-nuxt/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
13
14
  [npm-version-href]: https://npmjs.com/package/usemods-nuxt
14
15
 
@@ -18,12 +19,11 @@ Auto-imported functions and modifiers for zippy Nuxt developers.
18
19
  [license-src]: https://img.shields.io/npm/l/usemods-nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
19
20
  [license-href]: https://npmjs.com/package/usemods-nuxt
20
21
 
21
- [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
22
- [nuxt-href]: https://nuxt.com
23
-
24
- [![CI](https://github.com/LittleFoxCompany/usemods/actions/workflows/ci.yml/badge.svg)](https://github.com/LittleFoxCompany/usemods/actions/workflows/ci.yml)
22
+ [ci-src]: https://github.com/LittleFoxCompany/usemods/actions/workflows/ci.yml/badge.svg
23
+ [ci-href]: https://github.com/LittleFoxCompany/usemods/actions/workflows/ci.yml
25
24
 
26
- [![CodeQL](https://github.com/LittleFoxCompany/usemods/actions/workflows/github-code-scanning/codeql/badge.svg?branch=main)](https://github.com/LittleFoxCompany/usemods/actions/workflows/github-code-scanning/codeql)
25
+ [codeql-src]: https://github.com/LittleFoxCompany/usemods/actions/workflows/github-code-scanning/codeql/badge.svg?branch=main
26
+ [codeql-href]: https://github.com/LittleFoxCompany/usemods/actions/workflows/github-code-scanning/codeql
27
27
 
28
28
  ## Quick Setup
29
29
  ```bash
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "usemods-nuxt",
3
3
  "configKey": "usemods",
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.7.0",
7
7
  "unbuild": "2.0.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usemods-nuxt",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Zippy little modifiers and utilities for your Nuxt app.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@nuxt/kit": "^3.11.2",
35
- "usemods": "1.4.2"
35
+ "usemods": "1.4.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@nuxt/devtools": "^1.3.2",
@@ -1,37 +0,0 @@
1
- /**
2
- * Smoothly scrolls to the element with the specified ID without scuffing up your URLs.
3
- */
4
- export declare function scrollToAnchor(id: string): Promise<void>;
5
- /**
6
- * Toggles the body scroll with specified class names and returns a promise
7
- * @info Use your own class names, or ensure fixed is within your Tailwindcss JIT
8
- */
9
- export declare function toggleBodyScroll(className?: string, action?: 'add' | 'remove' | 'toggle'): Promise<void>;
10
- /**
11
- * Toggles the element scroll with specified class names and returns a promise
12
- */
13
- export declare function toggleElementScroll(element: HTMLElement): Promise<void>;
14
- /**
15
- * Copies a convereted string to the clipboard
16
- */
17
- export declare function copyToClipboard(value: string | number): Promise<void>;
18
- /**
19
- * Toggles the fullscreen mode
20
- */
21
- export declare function toggleFullScreen(): Promise<void>;
22
- /**
23
- * Resets a form to its initial state
24
- */
25
- export declare function resetForm(form: HTMLFormElement): Promise<void>;
26
- /**
27
- * Focuses on and scrolls to the first invalid input, select, or textarea element within a form.
28
- */
29
- export declare function focusOnInvalid(container: HTMLElement): Promise<void>;
30
- /**
31
- * Focuses on the nth element within the specified form, where 0 is the first element and -1 is the last element.
32
- */
33
- export declare function focusOnNth(container: HTMLElement, index?: number): Promise<void>;
34
- /**
35
- * Sets up a keyboard trap within an HTML element, allowing the focus to cycle between the first and last focusable elements when the Tab key is pressed.
36
- */
37
- export declare function focusTrap(container: HTMLElement): void;
@@ -1,142 +0,0 @@
1
- export function scrollToAnchor(id) {
2
- return new Promise((resolve, reject) => {
3
- setTimeout(() => {
4
- const selector = `#${id}`;
5
- const element = document.querySelector(selector);
6
- if (!element) {
7
- console.warn(`[MODS] Element with id '${id}' not found.`);
8
- reject(`Element with id '${id}' not found.`);
9
- return;
10
- }
11
- element.scrollIntoView({
12
- behavior: "smooth",
13
- block: "start"
14
- });
15
- resolve();
16
- }, 180);
17
- });
18
- }
19
- export function toggleBodyScroll(className = "fixed", action = "toggle") {
20
- return new Promise((resolve, reject) => {
21
- try {
22
- const body = document.body;
23
- const isFixed = body.classList.contains(className);
24
- const scrollY = isFixed ? parseInt(body.style.top, 10) : window.scrollY;
25
- body.style.top = isFixed ? "" : `-${scrollY}px`;
26
- if (action === "add") {
27
- body.classList.add(className);
28
- } else if (action === "remove") {
29
- body.classList.remove(className);
30
- } else {
31
- body.classList.toggle(className);
32
- }
33
- if (isFixed)
34
- window.scrollTo(0, -scrollY);
35
- resolve();
36
- } catch (error) {
37
- console.warn("[MODS] Failed to toggle body scroll.");
38
- reject(error);
39
- }
40
- });
41
- }
42
- export function toggleElementScroll(element) {
43
- return new Promise((resolve) => {
44
- if (!element) {
45
- console.warn("[MODS] Element is required to toggle scroll.");
46
- return resolve();
47
- }
48
- if (element.dataset.isScrollLocked === "true") {
49
- element.style.overflow = "";
50
- delete element.dataset.isScrollLocked;
51
- } else {
52
- element.style.overflow = "hidden";
53
- element.dataset.isScrollLocked = "true";
54
- }
55
- resolve();
56
- });
57
- }
58
- export async function copyToClipboard(value) {
59
- if (!navigator.clipboard || !navigator.clipboard.writeText) {
60
- throw new Error("Clipboard API is not available");
61
- }
62
- try {
63
- await navigator.clipboard.writeText(String(value));
64
- } catch (error) {
65
- console.error("Failed to copy text: ", error);
66
- throw error;
67
- }
68
- }
69
- export function toggleFullScreen() {
70
- return new Promise((resolve, reject) => {
71
- if (document.fullscreenElement) {
72
- document.exitFullscreen().then(resolve).catch(reject);
73
- } else {
74
- document.documentElement.requestFullscreen().then(resolve).catch(reject);
75
- }
76
- });
77
- }
78
- export function resetForm(form) {
79
- return new Promise((resolve, reject) => {
80
- try {
81
- form.reset();
82
- resolve();
83
- } catch (error) {
84
- reject(error);
85
- }
86
- });
87
- }
88
- export function focusOnInvalid(container) {
89
- return new Promise((resolve, reject) => {
90
- try {
91
- const input = container.querySelector("input:invalid, select:invalid, textarea:invalid");
92
- if (input) {
93
- input.focus();
94
- input.scrollIntoView({ behavior: "smooth", block: "center" });
95
- }
96
- resolve();
97
- } catch (error) {
98
- reject(error);
99
- }
100
- });
101
- }
102
- export function focusOnNth(container, index = 0) {
103
- return new Promise((resolve, reject) => {
104
- const elements = container.querySelectorAll("input, textarea, select");
105
- const elementIndex = index === -1 ? elements.length - 1 : index;
106
- if (elementIndex < 0 || elementIndex >= elements.length) {
107
- return reject(new Error(`Element at index ${index} is out of bounds.`));
108
- }
109
- const element = elements[elementIndex];
110
- if (!element || typeof element.focus !== "function") {
111
- return reject(new Error("Failed to focus on the element."));
112
- }
113
- try {
114
- element.focus({ preventScroll: true });
115
- element.scrollIntoView({ behavior: "smooth", block: "center" });
116
- resolve();
117
- } catch (error) {
118
- reject(new Error("Failed to focus on the element."));
119
- }
120
- });
121
- }
122
- export function focusTrap(container) {
123
- const focusableElements = container.querySelectorAll('a[href], button, textarea, input[type="text"], input[type="radio"], input[type="checkbox"], select');
124
- const firstFocusableElement = focusableElements[0];
125
- const lastFocusableElement = focusableElements[focusableElements.length - 1];
126
- container.addEventListener("keydown", (event) => {
127
- const isTabPressed = event.key === "Tab";
128
- if (!isTabPressed)
129
- return;
130
- if (event.shiftKey) {
131
- if (document.activeElement === firstFocusableElement) {
132
- lastFocusableElement.focus();
133
- event.preventDefault();
134
- }
135
- } else {
136
- if (document.activeElement === lastFocusableElement) {
137
- firstFocusableElement.focus();
138
- event.preventDefault();
139
- }
140
- }
141
- });
142
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Animate text by wrapping each character in a span with a delay.
3
- */
4
- export declare function animateText(text: string, options?: {
5
- splitBy?: 'word' | 'character';
6
- time?: number;
7
- unit?: 'ms' | 's';
8
- class?: string;
9
- }): string;
10
- /**
11
- * Animate a group of elements by wrapping each in a span with an incremental delay.
12
- */
@@ -1,21 +0,0 @@
1
- export function animateText(text, options = {}) {
2
- if (!text)
3
- return "";
4
- const { splitBy = "character", time = 0.1, unit = "s", class: cssClass = "" } = options;
5
- const delimiter = splitBy === "word" ? " " : "";
6
- const elements = text.split(delimiter);
7
- const result = elements.map((element, index) => {
8
- const delay = `${index * time}${unit}`;
9
- const spanStyle = "display: inline-block; position: relative;";
10
- const translateStyle = `position: absolute; top: 0; left: 0; animation-delay: ${delay};`;
11
- if (element === " " && splitBy === "character") {
12
- return '<span class="space" style="white-space: pre;"> </span>';
13
- } else {
14
- return `<span class="relative overflow-clip" style="${spanStyle}">
15
- <span class="ghost" style="visibility: hidden;">${element}</span>
16
- <span class="translate ${cssClass}" style="${translateStyle}">${element}</span>
17
- </span>`;
18
- }
19
- });
20
- return splitBy === "word" ? result.join(" ") : result.join("");
21
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Sort an array or object by a property.
3
- */
4
- export declare function dataSortBy(items: object | string[] | number[], options?: {
5
- property?: string;
6
- order?: 'asc' | 'desc';
7
- }): object | string[] | number[];
8
- /**
9
- * Reverse an array or object.
10
- */
11
- export declare function dataReverse(items: object | string[] | number[]): object | string[] | number[];
12
- /**
13
- * Returns single unique values within an array or object
14
- */
15
- export declare function dataRemoveDuplicates<T extends string | number>(...arrays: T[][]): T[];
16
- /**
17
- * Flatten an array of arrays or an object of objects into a single array or object. That was hard to say.
18
- */
19
- export declare function dataFlatten(items: object | any[]): object | any[];
20
- /**
21
- * Returns an array without a property or properties.
22
- */
23
- export declare function dataWithout(items: object | string[] | number[], properties: string | number | string[] | number[]): object | string[] | number[];
@@ -1,73 +0,0 @@
1
- import { isObject } from "./validators.js";
2
- export function dataSortBy(items, options) {
3
- const defaultOptions = { order: "asc" };
4
- const { property, order } = { ...defaultOptions, ...options };
5
- const compare = (a, b) => {
6
- let valueA, valueB;
7
- if (property) {
8
- valueA = a[property];
9
- valueB = b[property];
10
- } else {
11
- valueA = a;
12
- valueB = b;
13
- }
14
- if (valueA < valueB) {
15
- return order === "asc" ? -1 : 1;
16
- } else if (valueA > valueB) {
17
- return order === "asc" ? 1 : -1;
18
- } else {
19
- return 0;
20
- }
21
- };
22
- if (Array.isArray(items)) {
23
- return items.sort(compare);
24
- } else {
25
- return items;
26
- }
27
- }
28
- export function dataReverse(items) {
29
- if (Array.isArray(items) && items.length === 0 || !Array.isArray(items) && Object.keys(items).length === 0) {
30
- console.warn("[MODS] Warning: dataReverse() expects an object or array as the first argument.");
31
- return items;
32
- }
33
- if (isObject(items)) {
34
- const entries = Object.entries(items);
35
- return Object.fromEntries(entries.reverse());
36
- } else {
37
- return items.reverse();
38
- }
39
- }
40
- export function dataRemoveDuplicates(...arrays) {
41
- const mergedArray = arrays.flat();
42
- return Array.from(new Set(mergedArray));
43
- }
44
- export function dataFlatten(items) {
45
- if (isObject(items)) {
46
- let flattenObject = function(obj, parentKey = "") {
47
- for (const [key, value] of Object.entries(obj)) {
48
- const newKey = parentKey ? `${parentKey}.${key}` : key;
49
- if (isObject(value)) {
50
- flattenObject(value, newKey);
51
- } else {
52
- flattened[newKey] = value;
53
- }
54
- }
55
- };
56
- const flattened = {};
57
- flattenObject(items);
58
- return flattened;
59
- } else if (Array.isArray(items)) {
60
- return items.flatMap((item) => Array.isArray(item) ? dataFlatten(item) : item);
61
- } else {
62
- return items;
63
- }
64
- }
65
- export function dataWithout(items, properties) {
66
- const propertyArray = Array.isArray(properties) ? properties : [properties];
67
- if (isObject(items)) {
68
- const entries = Object.entries(items);
69
- return Object.fromEntries(entries.filter(([key]) => !propertyArray.includes(key)));
70
- } else {
71
- return items.filter((item) => !propertyArray.includes(item));
72
- }
73
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * Detect the current scroll position of the window
3
- */
4
- export declare function detectScrollPosition(): {
5
- x: number;
6
- y: number;
7
- };
8
- /**
9
- * Detect the absolute mouse position with the page
10
- * @info Don't forget to add a mousemove event listener to the window
11
- */
12
- export declare function detectMousePosition(event: MouseEvent): {
13
- x: number;
14
- y: number;
15
- };
16
- /**
17
- * Detect the relative mouse position with the window size and returns a percentage value
18
- * @info Don't forget to add a mousemove event listener to the window
19
- */
20
- export declare function detectRelativeMousePosition(event: MouseEvent): {
21
- x: number;
22
- y: number;
23
- };
24
- /**
25
- * Detect the browser's window size
26
- */
27
- export declare function detectWindowSize(): {
28
- width: number;
29
- height: number;
30
- };
31
- /**
32
- * Detect the screen or monitor size
33
- */
34
- export declare function detectScreenSize(): {
35
- width: number;
36
- height: number;
37
- };
38
- /**
39
- * Detect the current device type (Mobile or Desktop)
40
- */
41
- export declare function detectDevice(): string;
42
- /**
43
- * Detect the current operating system
44
- */
45
- export declare function detectOS(): string;
46
- /**
47
- * Detect if the browser window is currently active or hidden.
48
- */
49
- export declare function detectActiveBrowser(): boolean;
50
- /**
51
- * Detect the current color scheme (Light or Dark)
52
- */
53
- export declare function detectColorScheme(): string;
54
- /**
55
- * Detect the current user's Timezone
56
- */
57
- export declare function detectUserTimezone(): string;
58
- /**
59
- * Detect the currect device orientation
60
- */
61
- export declare function detectDeviceOrientation(): string;
62
- /**
63
- * Detect the current breakpoint based on Tailwind CSS breakpoints
64
- */
65
- export declare function detectBreakpoint(): string;
66
- /**
67
- * Detect the current network status of the user (Online or Offline)
68
- */
69
- export declare function detectNetworkStatus(): string;
70
- /**
71
- * Returns the current URL
72
- */
73
- export declare function detectUrl(): string;
74
- /**
75
- * Returns the path of the current URL in an array
76
- */
77
- export declare function detectUrlPath(): string[];
78
- /**
79
- * Returns a value from the URL by name
80
- */
81
- export declare function detectUrlParams(): {
82
- [key: string]: string;
83
- }[] | null;
84
- /**
85
- * Returns a value from the URL hash by name
86
- */
87
- export declare function detectUrlHash(): string | null;
88
- /**
89
- * Returns the current host or domain name from the URL
90
- */
91
- export declare function detectHost(): string;
92
- /**
93
- * Returns the current hostname from the URL
94
- */
95
- export declare function detectHostName(): string;
96
- /**
97
- * Returns the current port
98
- */
99
- export declare function detectPort(): string;
100
- /**
101
- * Detects if the element is currently in the viewport
102
- */
103
- /**
104
- * Detects if the element is currently in the container via ID
105
- */
106
- /**
107
- * Detect any container breakpoint based on Tailwind CSS breakpoints
108
- */
109
- /**
110
- * Detect the container size via ID
111
- */
@@ -1,105 +0,0 @@
1
- export function detectScrollPosition() {
2
- return {
3
- x: window.scrollX,
4
- y: window.scrollY
5
- };
6
- }
7
- export function detectMousePosition(event) {
8
- return {
9
- x: event.pageX,
10
- y: event.pageY
11
- };
12
- }
13
- export function detectRelativeMousePosition(event) {
14
- const { innerWidth, innerHeight } = window;
15
- return {
16
- x: parseFloat((event.clientX / innerWidth).toFixed(2)),
17
- y: parseFloat((event.clientY / innerHeight).toFixed(2))
18
- };
19
- }
20
- export function detectWindowSize() {
21
- return {
22
- width: window.innerWidth,
23
- height: window.innerHeight
24
- };
25
- }
26
- export function detectScreenSize() {
27
- return {
28
- width: window.screen.width,
29
- height: window.screen.height
30
- };
31
- }
32
- export function detectDevice() {
33
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop";
34
- }
35
- export function detectOS() {
36
- const userAgent = navigator.userAgent.toLowerCase();
37
- if (userAgent.includes("win"))
38
- return "Windows";
39
- if (userAgent.includes("mac"))
40
- return "Mac";
41
- if (userAgent.includes("linux"))
42
- return "Linux";
43
- if (userAgent.includes("x11"))
44
- return "UNIX";
45
- if (userAgent.includes("android"))
46
- return "Android";
47
- if (userAgent.includes("iphone"))
48
- return "iOS";
49
- return "Unknown";
50
- }
51
- export function detectActiveBrowser() {
52
- return !document.hidden;
53
- }
54
- export function detectColorScheme() {
55
- return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
56
- }
57
- export function detectUserTimezone() {
58
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
59
- }
60
- export function detectDeviceOrientation() {
61
- return window.screen.orientation.type;
62
- }
63
- export function detectBreakpoint() {
64
- const width = window.innerWidth;
65
- if (width < 640)
66
- return "xs";
67
- if (width < 768)
68
- return "sm";
69
- if (width < 1024)
70
- return "md";
71
- if (width < 1280)
72
- return "lg";
73
- if (width < 1536)
74
- return "xl";
75
- return "2xl";
76
- }
77
- export function detectNetworkStatus() {
78
- return navigator.onLine ? "Online" : "Offline";
79
- }
80
- export function detectUrl() {
81
- return window.location.href;
82
- }
83
- export function detectUrlPath() {
84
- return window.location.pathname.split("/").filter((p) => p);
85
- }
86
- export function detectUrlParams() {
87
- const searchParams = new URLSearchParams(window.location.search);
88
- const paramsArray = [];
89
- for (const [key, value] of searchParams.entries()) {
90
- paramsArray.push({ [key]: value });
91
- }
92
- return paramsArray.length > 0 ? paramsArray : null;
93
- }
94
- export function detectUrlHash() {
95
- return window.location.hash.replace("#", "");
96
- }
97
- export function detectHost() {
98
- return window.location.host;
99
- }
100
- export function detectHostName() {
101
- return window.location.hostname;
102
- }
103
- export function detectPort() {
104
- return window.location.port;
105
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * Check if you're a server-side user.
3
- */
4
- export declare function isServerSide(): boolean;
5
- /**
6
- * Adds detected devices as classes to your project's body class
7
- */
8
- export declare function addDeviceClasses(): void;
9
- /**
10
- * Check if you're a passionate iPhone fan.
11
- */
12
- export declare function isIos(): boolean;
13
- /**
14
- * Check if you're a zealous Android fan.
15
- */
16
- export declare function isAndroid(): boolean;
17
- /**
18
- * Check if you're a staunch Mac fan.
19
- */
20
- export declare function isMac(): boolean;
21
- /**
22
- * Check if you're a fervent Windows fan.
23
- */
24
- export declare function isWindows(): boolean;
25
- /**
26
- * Check if you're a devoted Linux fan.
27
- * @info Fun fact, most Linux users will tell you they have Linux before the function does.
28
- */
29
- export declare function isLinux(): boolean;
30
- /**
31
- * Check if you're a die-hard Chrome fan.
32
- */
33
- export declare function isChrome(): boolean;
34
- /**
35
- * Check if you're a dedicated Firefox fan.
36
- */
37
- export declare function isFirefox(): boolean;
38
- /**
39
- * Check if you're a lonely Safari fan.
40
- */
41
- export declare function isSafari(): boolean;
42
- /**
43
- * Check if you're an ardent Edge fan.
44
- */
45
- export declare function isEdge(): boolean;
46
- /**
47
- * Check if you're rocking a mobile
48
- */
49
- export declare function isMobile(): boolean;
50
- /**
51
- * Check if you're tablet user
52
- */
53
- export declare function isTablet(): boolean;
54
- /**
55
- * Check if you're pro desktop user
56
- */
57
- export declare function isDesktop(): boolean;
58
- /**
59
- * Check if you're portrait
60
- */
61
- export declare function isPortrait(): boolean;
62
- /**
63
- * Check if you're landscape
64
- */
65
- export declare function isLandscape(): boolean;
66
- /**
67
- * Check if you're a cyborg or a bot
68
- */
69
- export declare function isBot(): boolean;
70
- /**
71
- * Check if you're a human
72
- */
73
- export declare function isHuman(): boolean;
74
- /**
75
- * Check if you're a developer
76
- */
77
- export declare function isDeveloper(): boolean;