@v-c/util 1.0.12 → 1.0.14

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.
@@ -1,6 +1,6 @@
1
1
  import { ComponentPublicInstance, MaybeRef } from 'vue';
2
2
  export declare function isDOM(node: any): node is HTMLElement | SVGElement;
3
- export declare function getDOM(elementRef: MaybeRef): Element | Text;
3
+ export declare function getDOM(elementRef: MaybeRef): any;
4
4
  /**
5
5
  * Return if a node is a DOM node. Else will return by `findDOMNode`
6
6
  */
@@ -1,15 +1,18 @@
1
+ import canUseDom from "./canUseDom.js";
1
2
  import { unref } from "vue";
2
3
  function isDOM(node) {
3
4
  return node instanceof HTMLElement || node instanceof SVGElement;
4
5
  }
5
6
  function getDOM(elementRef) {
6
7
  const unrefElementRef = unref(elementRef);
8
+ if (!canUseDom()) return unrefElementRef;
7
9
  const dom = findDOMNode(unrefElementRef) || (unrefElementRef && typeof unrefElementRef === "object" ? findDOMNode(unrefElementRef.nativeElement) : null);
8
10
  if (dom && (dom.nodeType === 3 || dom.nodeType === 8) && dom.nextElementSibling) return dom.nextElementSibling;
9
11
  return dom;
10
12
  }
11
13
  function findDOMNode(_node) {
12
14
  const node = unref(_node);
15
+ if (!canUseDom()) return node;
13
16
  if (isDOM(node)) return node;
14
17
  else if (node && "$el" in node) return node.$el;
15
18
  return null;
@@ -0,0 +1,4 @@
1
+ function canUseDom() {
2
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
3
+ }
4
+ export { canUseDom };
@@ -1,15 +1,18 @@
1
+ import { canUseDom } from "./canUseDom.js";
1
2
  import { unref } from "vue";
2
3
  function isDOM(node) {
3
4
  return node instanceof HTMLElement || node instanceof SVGElement;
4
5
  }
5
6
  function getDOM(elementRef) {
6
7
  const unrefElementRef = unref(elementRef);
8
+ if (!canUseDom()) return unrefElementRef;
7
9
  const dom = findDOMNode(unrefElementRef) || (unrefElementRef && typeof unrefElementRef === "object" ? findDOMNode(unrefElementRef.nativeElement) : null);
8
10
  if (dom && (dom.nodeType === 3 || dom.nodeType === 8) && dom.nextElementSibling) return dom.nextElementSibling;
9
11
  return dom;
10
12
  }
11
13
  function findDOMNode(_node) {
12
14
  const node = unref(_node);
15
+ if (!canUseDom()) return node;
13
16
  if (isDOM(node)) return node;
14
17
  else if (node && "$el" in node) return node.$el;
15
18
  return null;
@@ -1 +1,9 @@
1
1
  export default function (id?: string): string;
2
+ /**
3
+ * Generate a valid HTML id from prefix and key.
4
+ * Sanitizes the key by replacing invalid characters with hyphens.
5
+ * @param prefix - The prefix for the id
6
+ * @param key - The key from React element, may contain spaces or invalid characters
7
+ * @returns A valid HTML id string
8
+ */
9
+ export declare function getId(prefix: string, key: string): string;
@@ -9,4 +9,7 @@ function useId_default(id) {
9
9
  if (process.env.NODE_ENV === "test") return "test-id";
10
10
  return vueId;
11
11
  }
12
- export { useId_default as default };
12
+ function getId(prefix, key) {
13
+ return `${prefix}-${key.replace(/[^a-zA-Z0-9_.:-]/g, "-")}`;
14
+ }
15
+ export { useId_default as default, getId };
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@v-c/util",
3
3
  "type": "module",
4
- "version": "1.0.12",
4
+ "version": "1.0.14",
5
5
  "description": "Vue3 components utils",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "author": {
10
+ "name": "aibayanyu20",
11
+ "email": "aibayanyu@qq.com",
12
+ "url": "https://yanyu.me"
13
+ },
9
14
  "exports": {
10
15
  ".": {
11
16
  "types": "./dist/index.d.ts",
@@ -59,11 +64,6 @@
59
64
  },
60
65
  "./package.json": "./package.json"
61
66
  },
62
- "author": {
63
- "name": "aibayanyu20",
64
- "email": "aibayanyu@qq.com",
65
- "url": "https://yanyu.me"
66
- },
67
67
  "main": "dist/index.js",
68
68
  "types": "dist/index.d.ts",
69
69
  "files": [