feat: initial commit - Phase 1 & 2 core features

This commit is contained in:
hiderfong
2026-04-22 17:07:33 +08:00
commit 1773bda06b
25005 changed files with 6252106 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { castArray as ensureArray } from "lodash-unified";
//#region ../../packages/utils/arrays.d.ts
declare const unique: <T>(arr: T[]) => T[];
declare const extractFirst: <T>(arr: T | T[]) => T;
type Many<T> = T | ReadonlyArray<T>;
/** like `_.castArray`, except falsy value returns empty array. */
declare const castArray: <T>(arr: Many<T>) => T[];
//#endregion
export { castArray, ensureArray, extractFirst, unique };
+17
View File
@@ -0,0 +1,17 @@
import { isArray } from "./types.mjs";
import { castArray as ensureArray } from "lodash-unified";
//#region ../../packages/utils/arrays.ts
const unique = (arr) => [...new Set(arr)];
const extractFirst = (arr) => {
return isArray(arr) ? arr[0] : arr;
};
/** like `_.castArray`, except falsy value returns empty array. */
const castArray = (arr) => {
if (!arr && arr !== 0) return [];
return isArray(arr) ? arr : [arr];
};
//#endregion
export { castArray, ensureArray, extractFirst, unique };
//# sourceMappingURL=arrays.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"arrays.mjs","names":[],"sources":["../../../../packages/utils/arrays.ts"],"sourcesContent":["import { isArray } from './types'\n\nexport const unique = <T>(arr: T[]) => [...new Set(arr)]\n\nexport const extractFirst = <T>(arr: T | T[]): T => {\n return isArray(arr) ? arr[0] : arr\n}\n\ntype Many<T> = T | ReadonlyArray<T>\n// TODO: rename to `ensureArray`\n/** like `_.castArray`, except falsy value returns empty array. */\nexport const castArray = <T>(arr: Many<T>): T[] => {\n if (!arr && (arr as any) !== 0) return []\n return isArray(arr) ? arr : [arr as T]\n}\n\n// TODO: remove import alias\n// avoid naming conflicts\nexport { castArray as ensureArray } from 'lodash-unified'\n"],"mappings":";;;;AAEA,MAAa,UAAa,QAAa,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;AAExD,MAAa,gBAAmB,QAAoB;AAClD,QAAO,QAAQ,IAAI,GAAG,IAAI,KAAK;;;AAMjC,MAAa,aAAgB,QAAsB;AACjD,KAAI,CAAC,OAAQ,QAAgB,EAAG,QAAO,EAAE;AACzC,QAAO,QAAQ,IAAI,GAAG,MAAM,CAAC,IAAS"}
+7
View File
@@ -0,0 +1,7 @@
import { isClient, isIOS } from "@vueuse/core";
//#region ../../packages/utils/browser.d.ts
declare const isFirefox: () => boolean;
declare const isAndroid: () => boolean;
//#endregion
export { isAndroid, isClient, isFirefox, isIOS };
+9
View File
@@ -0,0 +1,9 @@
import { isClient, isIOS } from "@vueuse/core";
//#region ../../packages/utils/browser.ts
const isFirefox = () => isClient && /firefox/i.test(window.navigator.userAgent);
const isAndroid = () => isClient && /android/i.test(window.navigator.userAgent);
//#endregion
export { isAndroid, isClient, isFirefox, isIOS };
//# sourceMappingURL=browser.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"browser.mjs","names":[],"sources":["../../../../packages/utils/browser.ts"],"sourcesContent":["import { isClient, isIOS } from '@vueuse/core'\n\nexport const isFirefox = (): boolean =>\n isClient && /firefox/i.test(window.navigator.userAgent)\n\nexport const isAndroid = (): boolean =>\n isClient && /android/i.test(window.navigator.userAgent)\n\nexport { isClient, isIOS }\n"],"mappings":";;;AAEA,MAAa,kBACX,YAAY,WAAW,KAAK,OAAO,UAAU,UAAU;AAEzD,MAAa,kBACX,YAAY,WAAW,KAAK,OAAO,UAAU,UAAU"}
+29
View File
@@ -0,0 +1,29 @@
//#region ../../packages/utils/dom/aria.d.ts
declare const isShadowRoot: (e: unknown) => e is ShadowRoot;
/**
* Determine if the testing element is visible on screen no matter if its on the viewport or not
*/
declare const isVisible: (element: HTMLElement) => boolean;
declare const obtainAllFocusableElements: (element: HTMLElement) => HTMLElement[];
/**
* @desc Determine if target element is focusable
* @param element {HTMLElement}
* @returns {Boolean} true if it is focusable
*/
declare const isFocusable: (element: HTMLElement) => boolean;
/**
* Trigger an event
* mouseenter, mouseleave, mouseover, keyup, change, click, etc.
* @param {HTMLElement} elm
* @param {String} name
* @param {*} opts
*/
declare const triggerEvent: (elm: HTMLElement, name: string, ...opts: Array<boolean>) => HTMLElement;
declare const isLeaf: (el: HTMLElement) => boolean;
declare const getSibling: (el: HTMLElement, distance: number, elClass: string) => Element | null;
declare const focusElement: (el?: HTMLElement | {
focus: () => void;
} | null, options?: FocusOptions) => void;
declare const focusNode: (el: HTMLElement) => void;
//#endregion
export { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent };
+79
View File
@@ -0,0 +1,79 @@
//#region ../../packages/utils/dom/aria.ts
const FOCUSABLE_ELEMENT_SELECTORS = `a[href],button:not([disabled]),button:not([hidden]),:not([tabindex="-1"]),input:not([disabled]),input:not([type="hidden"]),select:not([disabled]),textarea:not([disabled])`;
const isShadowRoot = (e) => {
if (typeof ShadowRoot === "undefined") return false;
return e instanceof ShadowRoot;
};
const isHTMLElement = (e) => {
if (typeof Element === "undefined") return false;
return e instanceof Element;
};
/**
* Determine if the testing element is visible on screen no matter if its on the viewport or not
*/
const isVisible = (element) => {
return getComputedStyle(element).position === "fixed" ? false : element.offsetParent !== null;
};
const obtainAllFocusableElements = (element) => {
return Array.from(element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS)).filter((item) => isFocusable(item) && isVisible(item));
};
/**
* @desc Determine if target element is focusable
* @param element {HTMLElement}
* @returns {Boolean} true if it is focusable
*/
const isFocusable = (element) => {
if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute("tabIndex") !== null) return true;
if (element.tabIndex < 0 || element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true") return false;
switch (element.nodeName) {
case "A": return !!element.href && element.rel !== "ignore";
case "INPUT": return !(element.type === "hidden" || element.type === "file");
case "BUTTON":
case "SELECT":
case "TEXTAREA": return true;
default: return false;
}
};
/**
* Trigger an event
* mouseenter, mouseleave, mouseover, keyup, change, click, etc.
* @param {HTMLElement} elm
* @param {String} name
* @param {*} opts
*/
const triggerEvent = function(elm, name, ...opts) {
let eventName;
if (name.includes("mouse") || name.includes("click")) eventName = "MouseEvents";
else if (name.includes("key")) eventName = "KeyboardEvent";
else eventName = "HTMLEvents";
const evt = document.createEvent(eventName);
evt.initEvent(name, ...opts);
elm.dispatchEvent(evt);
return elm;
};
const isLeaf = (el) => !el.getAttribute("aria-owns");
const getSibling = (el, distance, elClass) => {
const { parentNode } = el;
if (!parentNode) return null;
const siblings = parentNode.querySelectorAll(elClass);
return siblings[Array.prototype.indexOf.call(siblings, el) + distance] || null;
};
const focusElement = (el, options) => {
if (!el || !el.focus) return;
let cleanup = false;
if (isHTMLElement(el) && !isFocusable(el) && !el.getAttribute("tabindex")) {
el.setAttribute("tabindex", "-1");
cleanup = true;
}
el.focus(options);
if (isHTMLElement(el) && cleanup) el.removeAttribute("tabindex");
};
const focusNode = (el) => {
if (!el) return;
focusElement(el);
!isLeaf(el) && el.click();
};
//#endregion
export { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent };
//# sourceMappingURL=aria.mjs.map
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
//#region ../../packages/utils/dom/element.d.ts
type GetElement = <T extends string | HTMLElement | Window | null | undefined>(target: T) => T extends string ? HTMLElement | null : T;
declare const getElement: GetElement;
//#endregion
export { getElement };
+17
View File
@@ -0,0 +1,17 @@
import { isClient } from "../browser.mjs";
import { isString } from "../types.mjs";
//#region ../../packages/utils/dom/element.ts
const getElement = ((target) => {
if (!isClient || target === "") return null;
if (isString(target)) try {
return document.querySelector(target);
} catch {
return null;
}
return target;
});
//#endregion
export { getElement };
//# sourceMappingURL=element.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"element.mjs","names":[],"sources":["../../../../../packages/utils/dom/element.ts"],"sourcesContent":["import { isString } from '../types'\nimport { isClient } from '../browser'\n\ntype GetElement = <T extends string | HTMLElement | Window | null | undefined>(\n target: T\n) => T extends string ? HTMLElement | null : T\n\nexport const getElement = ((\n target: string | HTMLElement | Window | null | undefined\n) => {\n if (!isClient || target === '') return null\n if (isString(target)) {\n try {\n return document.querySelector<HTMLElement>(target)\n } catch {\n return null\n }\n }\n return target\n}) as GetElement\n"],"mappings":";;;;AAOA,MAAa,eACX,WACG;AACH,KAAI,CAAC,YAAY,WAAW,GAAI,QAAO;AACvC,KAAI,SAAS,OAAO,CAClB,KAAI;AACF,SAAO,SAAS,cAA2B,OAAO;SAC5C;AACN,SAAO;;AAGX,QAAO"}
+12
View File
@@ -0,0 +1,12 @@
//#region ../../packages/utils/dom/event.d.ts
declare const composeEventHandlers: <E>(theirsHandler?: (event: E) => boolean | void, oursHandler?: (event: E) => void, {
checkForDefaultPrevented
}?: {
checkForDefaultPrevented?: boolean | undefined;
}) => (event: E) => void;
type WhenMouseHandler = (e: PointerEvent) => any;
declare const whenMouse: (handler: WhenMouseHandler) => WhenMouseHandler;
declare const getEventCode: (event: KeyboardEvent) => string;
declare const getEventKey: (event: KeyboardEvent) => string;
//#endregion
export { composeEventHandlers, getEventCode, getEventKey, whenMouse };
+38
View File
@@ -0,0 +1,38 @@
import { EVENT_CODE } from "../../constants/aria.mjs";
import { isAndroid } from "../browser.mjs";
//#region ../../packages/utils/dom/event.ts
const composeEventHandlers = (theirsHandler, oursHandler, { checkForDefaultPrevented = true } = {}) => {
const handleEvent = (event) => {
const shouldPrevent = theirsHandler?.(event);
if (checkForDefaultPrevented === false || !shouldPrevent) return oursHandler?.(event);
};
return handleEvent;
};
const whenMouse = (handler) => {
return (e) => e.pointerType === "mouse" ? handler(e) : void 0;
};
const getEventCode = (event) => {
if (event.code && event.code !== "Unidentified") return event.code;
const key = getEventKey(event);
if (key) {
if (Object.values(EVENT_CODE).includes(key)) return key;
switch (key) {
case " ": return EVENT_CODE.space;
default: return "";
}
}
return "";
};
const getEventKey = (event) => {
let key = event.key && event.key !== "Unidentified" ? event.key : "";
if (!key && event.type === "keyup" && isAndroid()) {
const target = event.target;
key = target.value.charAt(target.selectionStart - 1);
}
return key;
};
//#endregion
export { composeEventHandlers, getEventCode, getEventKey, whenMouse };
//# sourceMappingURL=event.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"event.mjs","names":[],"sources":["../../../../../packages/utils/dom/event.ts"],"sourcesContent":["import { EVENT_CODE } from '@element-plus/constants'\nimport { isAndroid } from '../browser'\n\nexport const composeEventHandlers = <E>(\n theirsHandler?: (event: E) => boolean | void,\n oursHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {}\n) => {\n const handleEvent = (event: E) => {\n const shouldPrevent = theirsHandler?.(event)\n\n if (checkForDefaultPrevented === false || !shouldPrevent) {\n return oursHandler?.(event)\n }\n }\n return handleEvent\n}\n\ntype WhenMouseHandler = (e: PointerEvent) => any\nexport const whenMouse = (handler: WhenMouseHandler): WhenMouseHandler => {\n return (e: PointerEvent) =>\n e.pointerType === 'mouse' ? handler(e) : undefined\n}\n\nexport const getEventCode = (event: KeyboardEvent): string => {\n if (event.code && event.code !== 'Unidentified') return event.code\n // On android, event.code is always '' (see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code#browser_compatibility)\n const key = getEventKey(event)\n\n if (key) {\n if (Object.values(EVENT_CODE).includes(key)) return key\n\n switch (key) {\n case ' ':\n return EVENT_CODE.space\n default:\n return ''\n }\n }\n\n return ''\n}\n\nexport const getEventKey = (event: KeyboardEvent): string => {\n let key = event.key && event.key !== 'Unidentified' ? event.key : ''\n\n // On Android, event.key and event.code may not be useful when entering characters or space\n // So here we directly get the last character of the input\n // **only takes effect in the keyup event**\n if (!key && event.type === 'keyup' && isAndroid()) {\n const target = event.target as HTMLInputElement\n key = target.value.charAt(target.selectionStart! - 1)\n }\n\n return key\n}\n"],"mappings":";;;;AAGA,MAAa,wBACX,eACA,aACA,EAAE,2BAA2B,SAAS,EAAE,KACrC;CACH,MAAM,eAAe,UAAa;EAChC,MAAM,gBAAgB,gBAAgB,MAAM;AAE5C,MAAI,6BAA6B,SAAS,CAAC,cACzC,QAAO,cAAc,MAAM;;AAG/B,QAAO;;AAIT,MAAa,aAAa,YAAgD;AACxE,SAAQ,MACN,EAAE,gBAAgB,UAAU,QAAQ,EAAE,GAAG;;AAG7C,MAAa,gBAAgB,UAAiC;AAC5D,KAAI,MAAM,QAAQ,MAAM,SAAS,eAAgB,QAAO,MAAM;CAE9D,MAAM,MAAM,YAAY,MAAM;AAE9B,KAAI,KAAK;AACP,MAAI,OAAO,OAAO,WAAW,CAAC,SAAS,IAAI,CAAE,QAAO;AAEpD,UAAQ,KAAR;GACE,KAAK,IACH,QAAO,WAAW;GACpB,QACE,QAAO;;;AAIb,QAAO;;AAGT,MAAa,eAAe,UAAiC;CAC3D,IAAI,MAAM,MAAM,OAAO,MAAM,QAAQ,iBAAiB,MAAM,MAAM;AAKlE,KAAI,CAAC,OAAO,MAAM,SAAS,WAAW,WAAW,EAAE;EACjD,MAAM,SAAS,MAAM;AACrB,QAAM,OAAO,MAAM,OAAO,OAAO,iBAAkB,EAAE;;AAGvD,QAAO"}
+7
View File
@@ -0,0 +1,7 @@
import { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent } from "./aria.js";
import { composeEventHandlers, getEventCode, getEventKey, whenMouse } from "./event.js";
import { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer } from "./position.js";
import { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView } from "./scroll.js";
import { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle } from "./style.js";
import { getElement } from "./element.js";
export { addClass, addUnit, animateScrollTo, classNameToArray, composeEventHandlers, focusElement, focusNode, getClientXY, getElement, getEventCode, getEventKey, getOffsetTop, getOffsetTopDistance, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, getSibling, getStyle, hasClass, isFocusable, isInContainer, isLeaf, isScroll, isShadowRoot, isVisible, obtainAllFocusableElements, removeClass, removeStyle, scrollIntoView, setStyle, triggerEvent, whenMouse };
+8
View File
@@ -0,0 +1,8 @@
import { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent } from "./aria.mjs";
import { composeEventHandlers, getEventCode, getEventKey, whenMouse } from "./event.mjs";
import { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer } from "./position.mjs";
import { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle } from "./style.mjs";
import { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView } from "./scroll.mjs";
import { getElement } from "./element.mjs";
export { addClass, addUnit, animateScrollTo, classNameToArray, composeEventHandlers, focusElement, focusNode, getClientXY, getElement, getEventCode, getEventKey, getOffsetTop, getOffsetTopDistance, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, getSibling, getStyle, hasClass, isFocusable, isInContainer, isLeaf, isScroll, isShadowRoot, isVisible, obtainAllFocusableElements, removeClass, removeStyle, scrollIntoView, setStyle, triggerEvent, whenMouse };
+10
View File
@@ -0,0 +1,10 @@
//#region ../../packages/utils/dom/position.d.ts
declare const isInContainer: (el?: Element, container?: Element | Window) => boolean;
declare const getOffsetTop: (el: HTMLElement) => number;
declare const getOffsetTopDistance: (el: HTMLElement, containerEl: HTMLElement) => number;
declare const getClientXY: (event: MouseEvent | TouchEvent) => {
clientX: number;
clientY: number;
};
//#endregion
export { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer };
+50
View File
@@ -0,0 +1,50 @@
import { isClient } from "../browser.mjs";
//#region ../../packages/utils/dom/position.ts
const isInContainer = (el, container) => {
if (!isClient || !el || !container) return false;
const elRect = el.getBoundingClientRect();
let containerRect;
if (container instanceof Element) containerRect = container.getBoundingClientRect();
else containerRect = {
top: 0,
right: window.innerWidth,
bottom: window.innerHeight,
left: 0
};
return elRect.top < containerRect.bottom && elRect.bottom > containerRect.top && elRect.right > containerRect.left && elRect.left < containerRect.right;
};
const getOffsetTop = (el) => {
let offset = 0;
let parent = el;
while (parent) {
offset += parent.offsetTop;
parent = parent.offsetParent;
}
return offset;
};
const getOffsetTopDistance = (el, containerEl) => {
return Math.abs(getOffsetTop(el) - getOffsetTop(containerEl));
};
const getClientXY = (event) => {
let clientX;
let clientY;
if (event.type === "touchend") {
clientY = event.changedTouches[0].clientY;
clientX = event.changedTouches[0].clientX;
} else if (event.type.startsWith("touch")) {
clientY = event.touches[0].clientY;
clientX = event.touches[0].clientX;
} else {
clientY = event.clientY;
clientX = event.clientX;
}
return {
clientX,
clientY
};
};
//#endregion
export { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer };
//# sourceMappingURL=position.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"position.mjs","names":[],"sources":["../../../../../packages/utils/dom/position.ts"],"sourcesContent":["import { isClient } from '../browser'\n\nexport const isInContainer = (\n el?: Element,\n container?: Element | Window\n): boolean => {\n if (!isClient || !el || !container) return false\n\n const elRect = el.getBoundingClientRect()\n\n let containerRect: Pick<DOMRect, 'top' | 'bottom' | 'left' | 'right'>\n if (container instanceof Element) {\n containerRect = container.getBoundingClientRect()\n } else {\n containerRect = {\n top: 0,\n right: window.innerWidth,\n bottom: window.innerHeight,\n left: 0,\n }\n }\n return (\n elRect.top < containerRect.bottom &&\n elRect.bottom > containerRect.top &&\n elRect.right > containerRect.left &&\n elRect.left < containerRect.right\n )\n}\n\nexport const getOffsetTop = (el: HTMLElement) => {\n let offset = 0\n let parent = el\n\n while (parent) {\n offset += parent.offsetTop\n parent = parent.offsetParent as HTMLElement\n }\n\n return offset\n}\n\nexport const getOffsetTopDistance = (\n el: HTMLElement,\n containerEl: HTMLElement\n) => {\n return Math.abs(getOffsetTop(el) - getOffsetTop(containerEl))\n}\n\nexport const getClientXY = (event: MouseEvent | TouchEvent) => {\n let clientX: number\n let clientY: number\n if (event.type === 'touchend') {\n clientY = (event as TouchEvent).changedTouches[0].clientY\n clientX = (event as TouchEvent).changedTouches[0].clientX\n } else if (event.type.startsWith('touch')) {\n clientY = (event as TouchEvent).touches[0].clientY\n clientX = (event as TouchEvent).touches[0].clientX\n } else {\n clientY = (event as MouseEvent).clientY\n clientX = (event as MouseEvent).clientX\n }\n return {\n clientX,\n clientY,\n }\n}\n"],"mappings":";;;AAEA,MAAa,iBACX,IACA,cACY;AACZ,KAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAW,QAAO;CAE3C,MAAM,SAAS,GAAG,uBAAuB;CAEzC,IAAI;AACJ,KAAI,qBAAqB,QACvB,iBAAgB,UAAU,uBAAuB;KAEjD,iBAAgB;EACd,KAAK;EACL,OAAO,OAAO;EACd,QAAQ,OAAO;EACf,MAAM;EACP;AAEH,QACE,OAAO,MAAM,cAAc,UAC3B,OAAO,SAAS,cAAc,OAC9B,OAAO,QAAQ,cAAc,QAC7B,OAAO,OAAO,cAAc;;AAIhC,MAAa,gBAAgB,OAAoB;CAC/C,IAAI,SAAS;CACb,IAAI,SAAS;AAEb,QAAO,QAAQ;AACb,YAAU,OAAO;AACjB,WAAS,OAAO;;AAGlB,QAAO;;AAGT,MAAa,wBACX,IACA,gBACG;AACH,QAAO,KAAK,IAAI,aAAa,GAAG,GAAG,aAAa,YAAY,CAAC;;AAG/D,MAAa,eAAe,UAAmC;CAC7D,IAAI;CACJ,IAAI;AACJ,KAAI,MAAM,SAAS,YAAY;AAC7B,YAAW,MAAqB,eAAe,GAAG;AAClD,YAAW,MAAqB,eAAe,GAAG;YACzC,MAAM,KAAK,WAAW,QAAQ,EAAE;AACzC,YAAW,MAAqB,QAAQ,GAAG;AAC3C,YAAW,MAAqB,QAAQ,GAAG;QACtC;AACL,YAAW,MAAqB;AAChC,YAAW,MAAqB;;AAElC,QAAO;EACL;EACA;EACD"}
+14
View File
@@ -0,0 +1,14 @@
//#region ../../packages/utils/dom/scroll.d.ts
declare const isScroll: (el: HTMLElement, isVertical?: boolean) => boolean;
declare const getScrollContainer: (el: HTMLElement, isVertical?: boolean) => Window | HTMLElement | undefined;
declare const getScrollBarWidth: (namespace: string) => number;
/**
* Scroll with in the container element, positioning the **selected** element at the top
* of the container
*/
declare function scrollIntoView(container: HTMLElement, selected: HTMLElement): void;
declare function animateScrollTo(container: HTMLElement | Window, from: number, to: number, duration: number, callback?: unknown): () => void;
declare const getScrollElement: (target: HTMLElement, container: HTMLElement | Window) => HTMLElement;
declare const getScrollTop: (container: HTMLElement | Window) => number;
//#endregion
export { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView };
+109
View File
@@ -0,0 +1,109 @@
import { isShadowRoot } from "./aria.mjs";
import { isClient } from "../browser.mjs";
import { easeInOutCubic } from "../easings.mjs";
import { isFunction, isWindow } from "../types.mjs";
import { cAF, rAF } from "../raf.mjs";
import { getStyle } from "./style.mjs";
//#region ../../packages/utils/dom/scroll.ts
const isScroll = (el, isVertical) => {
if (!isClient) return false;
const key = {
undefined: "overflow",
true: "overflow-y",
false: "overflow-x"
}[String(isVertical)];
const overflow = getStyle(el, key);
return [
"scroll",
"auto",
"overlay"
].some((s) => overflow.includes(s));
};
const getScrollContainer = (el, isVertical) => {
if (!isClient) return;
let parent = el;
while (parent) {
if ([
window,
document,
document.documentElement
].includes(parent)) return window;
if (isScroll(parent, isVertical)) return parent;
if (isShadowRoot(parent)) parent = parent.host;
else parent = parent.parentNode;
}
return parent;
};
let scrollBarWidth;
const getScrollBarWidth = (namespace) => {
if (!isClient) return 0;
if (scrollBarWidth !== void 0) return scrollBarWidth;
const outer = document.createElement("div");
outer.className = `${namespace}-scrollbar__wrap`;
outer.style.visibility = "hidden";
outer.style.width = "100px";
outer.style.position = "absolute";
outer.style.top = "-9999px";
document.body.appendChild(outer);
const widthNoScroll = outer.offsetWidth;
outer.style.overflow = "scroll";
const inner = document.createElement("div");
inner.style.width = "100%";
outer.appendChild(inner);
const widthWithScroll = inner.offsetWidth;
outer.parentNode?.removeChild(outer);
scrollBarWidth = widthNoScroll - widthWithScroll;
return scrollBarWidth;
};
/**
* Scroll with in the container element, positioning the **selected** element at the top
* of the container
*/
function scrollIntoView(container, selected) {
if (!isClient) return;
if (!selected) {
container.scrollTop = 0;
return;
}
const offsetParents = [];
let pointer = selected.offsetParent;
while (pointer !== null && container !== pointer && container.contains(pointer)) {
offsetParents.push(pointer);
pointer = pointer.offsetParent;
}
const top = selected.offsetTop + offsetParents.reduce((prev, curr) => prev + curr.offsetTop, 0);
const bottom = top + selected.offsetHeight;
const viewRectTop = container.scrollTop;
const viewRectBottom = viewRectTop + container.clientHeight;
if (top < viewRectTop) container.scrollTop = top;
else if (bottom > viewRectBottom) container.scrollTop = bottom - container.clientHeight;
}
function animateScrollTo(container, from, to, duration, callback) {
const startTime = Date.now();
let handle;
const scroll = () => {
const time = Date.now() - startTime;
const nextScrollTop = easeInOutCubic(time > duration ? duration : time, from, to, duration);
if (isWindow(container)) container.scrollTo(window.pageXOffset, nextScrollTop);
else container.scrollTop = nextScrollTop;
if (time < duration) handle = rAF(scroll);
else if (isFunction(callback)) callback();
};
scroll();
return () => {
handle && cAF(handle);
};
}
const getScrollElement = (target, container) => {
if (isWindow(container)) return target.ownerDocument.documentElement;
return container;
};
const getScrollTop = (container) => {
if (isWindow(container)) return window.scrollY;
return container.scrollTop;
};
//#endregion
export { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView };
//# sourceMappingURL=scroll.mjs.map
File diff suppressed because one or more lines are too long
+13
View File
@@ -0,0 +1,13 @@
import { CSSProperties } from "vue";
//#region ../../packages/utils/dom/style.d.ts
declare const classNameToArray: (cls?: string) => string[];
declare const hasClass: (el: Element, cls: string) => boolean;
declare const addClass: (el: Element, cls: string) => void;
declare const removeClass: (el: Element, cls: string) => void;
declare const getStyle: (element: HTMLElement, styleName: keyof CSSProperties) => string;
declare const setStyle: (element: HTMLElement, styleName: CSSProperties | keyof CSSProperties, value?: string | number) => void;
declare const removeStyle: (element: HTMLElement, style: CSSProperties | keyof CSSProperties) => void;
declare function addUnit(value?: string | number, defaultUnit?: string): string | undefined;
//#endregion
export { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle };
+59
View File
@@ -0,0 +1,59 @@
import { isShadowRoot } from "./aria.mjs";
import { isClient } from "../browser.mjs";
import { isNumber, isObject, isString, isStringNumber } from "../types.mjs";
import { camelize } from "../strings.mjs";
import { entriesOf, keysOf } from "../objects.mjs";
import { debugWarn } from "../error.mjs";
//#region ../../packages/utils/dom/style.ts
const SCOPE = "utils/dom/style";
const classNameToArray = (cls = "") => cls.split(" ").filter((item) => !!item.trim());
const hasClass = (el, cls) => {
if (!el || !cls) return false;
if (cls.includes(" ")) throw new Error("className should not contain space.");
return el.classList.contains(cls);
};
const addClass = (el, cls) => {
if (!el || !cls.trim()) return;
el.classList.add(...classNameToArray(cls));
};
const removeClass = (el, cls) => {
if (!el || !cls.trim()) return;
el.classList.remove(...classNameToArray(cls));
};
const getStyle = (element, styleName) => {
if (!isClient || !element || !styleName || isShadowRoot(element)) return "";
let key = camelize(styleName);
if (key === "float") key = "cssFloat";
try {
const style = element.style[key];
if (style) return style;
const computed = document.defaultView?.getComputedStyle(element, "");
return computed ? computed[key] : "";
} catch {
return element.style[key];
}
};
const setStyle = (element, styleName, value) => {
if (!element || !styleName) return;
if (isObject(styleName)) entriesOf(styleName).forEach(([prop, value]) => setStyle(element, prop, value));
else {
const key = camelize(styleName);
element.style[key] = value;
}
};
const removeStyle = (element, style) => {
if (!element || !style) return;
if (isObject(style)) keysOf(style).forEach((prop) => removeStyle(element, prop));
else setStyle(element, style, "");
};
function addUnit(value, defaultUnit = "px") {
if (!value && value !== 0) return "";
if (isNumber(value) || isStringNumber(value)) return `${value}${defaultUnit}`;
else if (isString(value)) return value;
debugWarn(SCOPE, "binding value must be a string or number");
}
//#endregion
export { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle };
//# sourceMappingURL=style.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"style.mjs","names":[],"sources":["../../../../../packages/utils/dom/style.ts"],"sourcesContent":["import { isNumber, isObject, isString, isStringNumber } from '../types'\nimport { isClient } from '../browser'\nimport { camelize } from '../strings'\nimport { entriesOf, keysOf } from '../objects'\nimport { debugWarn } from '../error'\nimport { isShadowRoot } from './aria'\n\nimport type { CSSProperties } from 'vue'\n\nconst SCOPE = 'utils/dom/style'\n\nexport const classNameToArray = (cls = '') =>\n cls.split(' ').filter((item) => !!item.trim())\n\nexport const hasClass = (el: Element, cls: string): boolean => {\n if (!el || !cls) return false\n if (cls.includes(' ')) throw new Error('className should not contain space.')\n return el.classList.contains(cls)\n}\n\nexport const addClass = (el: Element, cls: string) => {\n if (!el || !cls.trim()) return\n el.classList.add(...classNameToArray(cls))\n}\n\nexport const removeClass = (el: Element, cls: string) => {\n if (!el || !cls.trim()) return\n el.classList.remove(...classNameToArray(cls))\n}\n\nexport const getStyle = (\n element: HTMLElement,\n styleName: keyof CSSProperties\n): string => {\n if (!isClient || !element || !styleName || isShadowRoot(element)) return ''\n\n let key = camelize(styleName)\n if (key === 'float') key = 'cssFloat'\n try {\n const style = (element.style as any)[key]\n if (style) return style\n const computed: any = document.defaultView?.getComputedStyle(element, '')\n return computed ? computed[key] : ''\n } catch {\n return (element.style as any)[key]\n }\n}\n\nexport const setStyle = (\n element: HTMLElement,\n styleName: CSSProperties | keyof CSSProperties,\n value?: string | number\n) => {\n if (!element || !styleName) return\n\n if (isObject(styleName)) {\n entriesOf(styleName).forEach(([prop, value]) =>\n setStyle(element, prop, value)\n )\n } else {\n const key: any = camelize(styleName)\n element.style[key] = value as any\n }\n}\n\nexport const removeStyle = (\n element: HTMLElement,\n style: CSSProperties | keyof CSSProperties\n) => {\n if (!element || !style) return\n\n if (isObject(style)) {\n keysOf(style).forEach((prop) => removeStyle(element, prop))\n } else {\n setStyle(element, style, '')\n }\n}\n\nexport function addUnit(value?: string | number, defaultUnit = 'px') {\n if (!value && value !== 0) return ''\n if (isNumber(value) || isStringNumber(value)) {\n return `${value}${defaultUnit}`\n } else if (isString(value)) {\n return value\n }\n debugWarn(SCOPE, 'binding value must be a string or number')\n}\n"],"mappings":";;;;;;;;AASA,MAAM,QAAQ;AAEd,MAAa,oBAAoB,MAAM,OACrC,IAAI,MAAM,IAAI,CAAC,QAAQ,SAAS,CAAC,CAAC,KAAK,MAAM,CAAC;AAEhD,MAAa,YAAY,IAAa,QAAyB;AAC7D,KAAI,CAAC,MAAM,CAAC,IAAK,QAAO;AACxB,KAAI,IAAI,SAAS,IAAI,CAAE,OAAM,IAAI,MAAM,sCAAsC;AAC7E,QAAO,GAAG,UAAU,SAAS,IAAI;;AAGnC,MAAa,YAAY,IAAa,QAAgB;AACpD,KAAI,CAAC,MAAM,CAAC,IAAI,MAAM,CAAE;AACxB,IAAG,UAAU,IAAI,GAAG,iBAAiB,IAAI,CAAC;;AAG5C,MAAa,eAAe,IAAa,QAAgB;AACvD,KAAI,CAAC,MAAM,CAAC,IAAI,MAAM,CAAE;AACxB,IAAG,UAAU,OAAO,GAAG,iBAAiB,IAAI,CAAC;;AAG/C,MAAa,YACX,SACA,cACW;AACX,KAAI,CAAC,YAAY,CAAC,WAAW,CAAC,aAAa,aAAa,QAAQ,CAAE,QAAO;CAEzE,IAAI,MAAM,SAAS,UAAU;AAC7B,KAAI,QAAQ,QAAS,OAAM;AAC3B,KAAI;EACF,MAAM,QAAS,QAAQ,MAAc;AACrC,MAAI,MAAO,QAAO;EAClB,MAAM,WAAgB,SAAS,aAAa,iBAAiB,SAAS,GAAG;AACzE,SAAO,WAAW,SAAS,OAAO;SAC5B;AACN,SAAQ,QAAQ,MAAc;;;AAIlC,MAAa,YACX,SACA,WACA,UACG;AACH,KAAI,CAAC,WAAW,CAAC,UAAW;AAE5B,KAAI,SAAS,UAAU,CACrB,WAAU,UAAU,CAAC,SAAS,CAAC,MAAM,WACnC,SAAS,SAAS,MAAM,MAAM,CAC/B;MACI;EACL,MAAM,MAAW,SAAS,UAAU;AACpC,UAAQ,MAAM,OAAO;;;AAIzB,MAAa,eACX,SACA,UACG;AACH,KAAI,CAAC,WAAW,CAAC,MAAO;AAExB,KAAI,SAAS,MAAM,CACjB,QAAO,MAAM,CAAC,SAAS,SAAS,YAAY,SAAS,KAAK,CAAC;KAE3D,UAAS,SAAS,OAAO,GAAG;;AAIhC,SAAgB,QAAQ,OAAyB,cAAc,MAAM;AACnE,KAAI,CAAC,SAAS,UAAU,EAAG,QAAO;AAClC,KAAI,SAAS,MAAM,IAAI,eAAe,MAAM,CAC1C,QAAO,GAAG,QAAQ;UACT,SAAS,MAAM,CACxB,QAAO;AAET,WAAU,OAAO,2CAA2C"}
+4
View File
@@ -0,0 +1,4 @@
//#region ../../packages/utils/easings.d.ts
declare function easeInOutCubic(t: number, b: number, c: number, d: number): number;
//#endregion
export { easeInOutCubic };
+11
View File
@@ -0,0 +1,11 @@
//#region ../../packages/utils/easings.ts
function easeInOutCubic(t, b, c, d) {
const cc = c - b;
t /= d / 2;
if (t < 1) return cc / 2 * t * t * t + b;
return cc / 2 * ((t -= 2) * t * t + 2) + b;
}
//#endregion
export { easeInOutCubic };
//# sourceMappingURL=easings.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"easings.mjs","names":[],"sources":["../../../../packages/utils/easings.ts"],"sourcesContent":["export function easeInOutCubic(t: number, b: number, c: number, d: number) {\n const cc = c - b\n t /= d / 2\n if (t < 1) {\n return (cc / 2) * t * t * t + b\n }\n return (cc / 2) * ((t -= 2) * t * t + 2) + b\n}\n"],"mappings":";AAAA,SAAgB,eAAe,GAAW,GAAW,GAAW,GAAW;CACzE,MAAM,KAAK,IAAI;AACf,MAAK,IAAI;AACT,KAAI,IAAI,EACN,QAAQ,KAAK,IAAK,IAAI,IAAI,IAAI;AAEhC,QAAQ,KAAK,MAAO,KAAK,KAAK,IAAI,IAAI,KAAK"}
+6
View File
@@ -0,0 +1,6 @@
//#region ../../packages/utils/error.d.ts
declare function throwError(scope: string, m: string): never;
declare function debugWarn(err: Error): void;
declare function debugWarn(scope: string, message: string): void;
//#endregion
export { debugWarn, throwError };
+22
View File
@@ -0,0 +1,22 @@
import { isString } from "./types.mjs";
//#region ../../packages/utils/error.ts
var ElementPlusError = class extends Error {
constructor(m) {
super(m);
this.name = "ElementPlusError";
}
};
function throwError(scope, m) {
throw new ElementPlusError(`[${scope}] ${m}`);
}
function debugWarn(scope, message) {
{
const error = isString(scope) ? new ElementPlusError(`[${scope}] ${message}`) : scope;
console.warn(error);
}
}
//#endregion
export { debugWarn, throwError };
//# sourceMappingURL=error.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"error.mjs","names":[],"sources":["../../../../packages/utils/error.ts"],"sourcesContent":["import { isString } from './types'\n\nclass ElementPlusError extends Error {\n constructor(m: string) {\n super(m)\n this.name = 'ElementPlusError'\n }\n}\n\nexport function throwError(scope: string, m: string): never {\n throw new ElementPlusError(`[${scope}] ${m}`)\n}\n\nexport function debugWarn(err: Error): void\nexport function debugWarn(scope: string, message: string): void\nexport function debugWarn(scope: string | Error, message?: string): void {\n if (process.env.NODE_ENV !== 'production') {\n const error: Error = isString(scope)\n ? new ElementPlusError(`[${scope}] ${message}`)\n : scope\n // eslint-disable-next-line no-console\n console.warn(error)\n }\n}\n"],"mappings":";;;AAEA,IAAM,mBAAN,cAA+B,MAAM;CACnC,YAAY,GAAW;AACrB,QAAM,EAAE;AACR,OAAK,OAAO;;;AAIhB,SAAgB,WAAW,OAAe,GAAkB;AAC1D,OAAM,IAAI,iBAAiB,IAAI,MAAM,IAAI,IAAI;;AAK/C,SAAgB,UAAU,OAAuB,SAAwB;CAC5B;EACzC,MAAM,QAAe,SAAS,MAAM,GAChC,IAAI,iBAAiB,IAAI,MAAM,IAAI,UAAU,GAC7C;AAEJ,UAAQ,KAAK,MAAM"}
+2
View File
@@ -0,0 +1,2 @@
import { NOOP, toRawType } from "@vue/shared";
export { NOOP, toRawType };
+3
View File
@@ -0,0 +1,3 @@
import { NOOP, toRawType } from "@vue/shared";
export { NOOP, toRawType };
+7
View File
@@ -0,0 +1,7 @@
//#region ../../packages/utils/i18n.d.ts
/**
* @deprecated This function is deprecated and will be removed in future versions.
*/
declare const isKorean: (text: string) => boolean;
//#endregion
export { isKorean };
+9
View File
@@ -0,0 +1,9 @@
//#region ../../packages/utils/i18n.ts
/**
* @deprecated This function is deprecated and will be removed in future versions.
*/
const isKorean = (text) => /([\uAC00-\uD7AF\u3130-\u318F])+/gi.test(text);
//#endregion
export { isKorean };
//# sourceMappingURL=i18n.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"i18n.mjs","names":[],"sources":["../../../../packages/utils/i18n.ts"],"sourcesContent":["/**\n * @deprecated This function is deprecated and will be removed in future versions.\n */\nexport const isKorean = (text: string) =>\n /([\\uAC00-\\uD7AF\\u3130-\\u318F])+/gi.test(text)\n"],"mappings":";;;;AAGA,MAAa,YAAY,SACvB,oCAAoC,KAAK,KAAK"}
+34
View File
@@ -0,0 +1,34 @@
import { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent } from "./dom/aria.js";
import { composeEventHandlers, getEventCode, getEventKey, whenMouse } from "./dom/event.js";
import { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer } from "./dom/position.js";
import { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView } from "./dom/scroll.js";
import { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle } from "./dom/style.js";
import { getElement } from "./dom/element.js";
import "./dom/index.js";
import { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode } from "./vue/global-node.js";
import { CloseComponents, IconComponent, IconPropType, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType } from "./vue/icon.js";
import { EmitFn, SFCInstallWithContext, SFCWithInstall, SFCWithPropsDefaultsSetter } from "./vue/typescript.js";
import { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter } from "./vue/install.js";
import { IfNever, IfUnknown, UnknownToNever, Writable, WritableArray } from "./vue/props/util.js";
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./vue/props/runtime.js";
import { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, IfEpProp, IfNativePropType, NativePropType, ResolvePropType } from "./vue/props/types.js";
import { composeRefs } from "./vue/refs.js";
import { getComponentSize } from "./vue/size.js";
import { isValidComponentSize, isValidDatePickType } from "./vue/validator.js";
import { FlattenVNodes, PatchFlags, RawSlots, VNodeChildAtom, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf } from "./vue/vnode.js";
import "./vue/index.js";
import { castArray, ensureArray, extractFirst, unique } from "./arrays.js";
import { isAndroid, isClient, isFirefox, isIOS } from "./browser.js";
import { debugWarn, throwError } from "./error.js";
import { NOOP, toRawType } from "./functions.js";
import { isKorean } from "./i18n.js";
import { entriesOf, getProp, hasOwn, keysOf } from "./objects.js";
import { cAF, rAF } from "./raf.js";
import { generateId, getRandomInt } from "./rand.js";
import { camelize, capitalize, escapeStringRegexp, hyphenate, kebabCase } from "./strings.js";
import { isArray, isBoolean, isDate, isElement, isEmpty, isFunction, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isString, isStringNumber, isSymbol, isUndefined, isWindow } from "./types.js";
import { AlignItems, Arrayable, Awaitable, CSSProperties, FieldPath, HTMLElementCustomized, Mutable, Nullable, ObjectFit, ZIndexType, mutable } from "./typescript.js";
import { throttleByRaf } from "./throttleByRaf.js";
import { easeInOutCubic } from "./easings.js";
import { isGreaterThan } from "./numbers.js";
export { AlignItems, Arrayable, Awaitable, CSSProperties, CloseComponents, EmitFn, EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, FieldPath, FlattenVNodes, HTMLElementCustomized, IconComponent, IconPropType, IfEpProp, IfNativePropType, IfNever, IfUnknown, Mutable, NOOP, NativePropType, Nullable, ObjectFit, PatchFlags, RawSlots, ResolvePropType, SFCInstallWithContext, SFCWithInstall, SFCWithPropsDefaultsSetter, TypeComponents, TypeComponentsMap, UnknownToNever, VNodeChildAtom, ValidateComponentsMap, Writable, WritableArray, ZIndexType, addClass, addUnit, animateScrollTo, buildProp, buildProps, cAF, camelize, capitalize, castArray, changeGlobalNodesTarget, classNameToArray, composeEventHandlers, composeRefs, createGlobalNode, debugWarn, definePropType, easeInOutCubic, ensureArray, entriesOf, epPropKey, escapeStringRegexp, extractFirst, flattedChildren, focusElement, focusNode, generateId, getClientXY, getComponentSize, getElement, getEventCode, getEventKey, getFirstValidNode, getNormalizedProps, getOffsetTop, getOffsetTopDistance, getProp, getRandomInt, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, getSibling, getStyle, hasClass, hasOwn, hyphenate, iconPropType, isAndroid, isArray, isBoolean, isClient, isComment, isDate, isElement, isEmpty, isEpProp, isFirefox, isFocusable, isFragment, isFunction, isGreaterThan, isIOS, isInContainer, isKorean, isLeaf, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isScroll, isShadowRoot, isString, isStringNumber, isSymbol, isTemplate, isText, isUndefined, isValidComponentSize, isValidDatePickType, isValidElementNode, isVisible, isWindow, kebabCase, keysOf, mutable, obtainAllFocusableElements, rAF, removeClass, removeGlobalNode, removeStyle, renderBlock, renderIf, scrollIntoView, setStyle, throttleByRaf, throwError, toRawType, triggerEvent, unique, whenMouse, withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
+30
View File
@@ -0,0 +1,30 @@
import { focusElement, focusNode, getSibling, isFocusable, isLeaf, isShadowRoot, isVisible, obtainAllFocusableElements, triggerEvent } from "./dom/aria.mjs";
import { isAndroid, isClient, isFirefox, isIOS } from "./browser.mjs";
import { composeEventHandlers, getEventCode, getEventKey, whenMouse } from "./dom/event.mjs";
import { getClientXY, getOffsetTop, getOffsetTopDistance, isInContainer } from "./dom/position.mjs";
import { easeInOutCubic } from "./easings.mjs";
import { isArray, isBoolean, isDate, isElement, isEmpty, isFunction, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isString, isStringNumber, isSymbol, isUndefined, isWindow } from "./types.mjs";
import { cAF, rAF } from "./raf.mjs";
import { camelize, capitalize, escapeStringRegexp, hyphenate, kebabCase } from "./strings.mjs";
import { entriesOf, getProp, hasOwn, keysOf } from "./objects.mjs";
import { debugWarn, throwError } from "./error.mjs";
import { addClass, addUnit, classNameToArray, getStyle, hasClass, removeClass, removeStyle, setStyle } from "./dom/style.mjs";
import { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView } from "./dom/scroll.mjs";
import { getElement } from "./dom/element.mjs";
import { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode } from "./vue/global-node.mjs";
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./vue/props/runtime.mjs";
import { CloseComponents, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType } from "./vue/icon.mjs";
import { NOOP, toRawType } from "./functions.mjs";
import { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter } from "./vue/install.mjs";
import { composeRefs } from "./vue/refs.mjs";
import { getComponentSize } from "./vue/size.mjs";
import { isValidComponentSize, isValidDatePickType } from "./vue/validator.mjs";
import { PatchFlags, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf } from "./vue/vnode.mjs";
import { castArray, ensureArray, extractFirst, unique } from "./arrays.mjs";
import { isKorean } from "./i18n.mjs";
import { generateId, getRandomInt } from "./rand.mjs";
import { mutable } from "./typescript.mjs";
import { throttleByRaf } from "./throttleByRaf.mjs";
import { isGreaterThan } from "./numbers.mjs";
export { CloseComponents, NOOP, PatchFlags, TypeComponents, TypeComponentsMap, ValidateComponentsMap, addClass, addUnit, animateScrollTo, buildProp, buildProps, cAF, camelize, capitalize, castArray, changeGlobalNodesTarget, classNameToArray, composeEventHandlers, composeRefs, createGlobalNode, debugWarn, definePropType, easeInOutCubic, ensureArray, entriesOf, epPropKey, escapeStringRegexp, extractFirst, flattedChildren, focusElement, focusNode, generateId, getClientXY, getComponentSize, getElement, getEventCode, getEventKey, getFirstValidNode, getNormalizedProps, getOffsetTop, getOffsetTopDistance, getProp, getRandomInt, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, getSibling, getStyle, hasClass, hasOwn, hyphenate, iconPropType, isAndroid, isArray, isBoolean, isClient, isComment, isDate, isElement, isEmpty, isEpProp, isFirefox, isFocusable, isFragment, isFunction, isGreaterThan, isIOS, isInContainer, isKorean, isLeaf, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isScroll, isShadowRoot, isString, isStringNumber, isSymbol, isTemplate, isText, isUndefined, isValidComponentSize, isValidDatePickType, isValidElementNode, isVisible, isWindow, kebabCase, keysOf, mutable, obtainAllFocusableElements, rAF, removeClass, removeGlobalNode, removeStyle, renderBlock, renderIf, scrollIntoView, setStyle, throttleByRaf, throwError, toRawType, triggerEvent, unique, whenMouse, withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
+9
View File
@@ -0,0 +1,9 @@
//#region ../../packages/utils/numbers.d.ts
/**
* Due to browser rendering and calculation precision loss issues,
* boundary checks cannot be based solely on value equality;
* a certain range of fluctuation is permissible.
*/
declare function isGreaterThan(a: number, b: number, epsilon?: number): boolean;
//#endregion
export { isGreaterThan };
+13
View File
@@ -0,0 +1,13 @@
//#region ../../packages/utils/numbers.ts
/**
* Due to browser rendering and calculation precision loss issues,
* boundary checks cannot be based solely on value equality;
* a certain range of fluctuation is permissible.
*/
function isGreaterThan(a, b, epsilon = .03) {
return a - b > epsilon;
}
//#endregion
export { isGreaterThan };
//# sourceMappingURL=numbers.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"numbers.mjs","names":[],"sources":["../../../../packages/utils/numbers.ts"],"sourcesContent":["/**\n * Due to browser rendering and calculation precision loss issues,\n * boundary checks cannot be based solely on value equality;\n * a certain range of fluctuation is permissible.\n */\nexport function isGreaterThan(a: number, b: number, epsilon = 0.03) {\n return a - b > epsilon\n}\n"],"mappings":";;;;;;AAKA,SAAgB,cAAc,GAAW,GAAW,UAAU,KAAM;AAClE,QAAO,IAAI,IAAI"}
+12
View File
@@ -0,0 +1,12 @@
import { Arrayable } from "./typescript.js";
import "./index.js";
import { hasOwn } from "@vue/shared";
//#region ../../packages/utils/objects.d.ts
declare const keysOf: <T extends object>(arr: T) => Array<keyof T>;
declare const entriesOf: <T extends object>(arr: T) => [keyof T, T[keyof T]][];
declare const getProp: <T = any>(obj: Record<string, any>, path: Arrayable<string>, defaultValue?: any) => {
value: T;
};
//#endregion
export { entriesOf, getProp, hasOwn, keysOf };
+20
View File
@@ -0,0 +1,20 @@
import { hasOwn } from "@vue/shared";
import { get, set } from "lodash-unified";
//#region ../../packages/utils/objects.ts
const keysOf = (arr) => Object.keys(arr);
const entriesOf = (arr) => Object.entries(arr);
const getProp = (obj, path, defaultValue) => {
return {
get value() {
return get(obj, path, defaultValue);
},
set value(val) {
set(obj, path, val);
}
};
};
//#endregion
export { entriesOf, getProp, hasOwn, keysOf };
//# sourceMappingURL=objects.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"objects.mjs","names":[],"sources":["../../../../packages/utils/objects.ts"],"sourcesContent":["import { get, set } from 'lodash-unified'\n\nimport type { Arrayable } from '.'\n\nexport const keysOf = <T extends object>(arr: T) =>\n Object.keys(arr) as Array<keyof T>\nexport const entriesOf = <T extends object>(arr: T) =>\n Object.entries(arr) as [keyof T, T[keyof T]][]\nexport { hasOwn } from '@vue/shared'\n\nexport const getProp = <T = any>(\n obj: Record<string, any>,\n path: Arrayable<string>,\n defaultValue?: any\n): { value: T } => {\n return {\n get value() {\n return get(obj, path, defaultValue)\n },\n set value(val: any) {\n set(obj, path, val)\n },\n }\n}\n"],"mappings":";;;;AAIA,MAAa,UAA4B,QACvC,OAAO,KAAK,IAAI;AAClB,MAAa,aAA+B,QAC1C,OAAO,QAAQ,IAAI;AAGrB,MAAa,WACX,KACA,MACA,iBACiB;AACjB,QAAO;EACL,IAAI,QAAQ;AACV,UAAO,IAAI,KAAK,MAAM,aAAa;;EAErC,IAAI,MAAM,KAAU;AAClB,OAAI,KAAK,MAAM,IAAI;;EAEtB"}
+5
View File
@@ -0,0 +1,5 @@
//#region ../../packages/utils/raf.d.ts
declare const rAF: (fn: () => void) => number;
declare const cAF: (handle: number) => void;
//#endregion
export { cAF, rAF };
+9
View File
@@ -0,0 +1,9 @@
import { isClient } from "./browser.mjs";
//#region ../../packages/utils/raf.ts
const rAF = (fn) => isClient ? window.requestAnimationFrame(fn) : setTimeout(fn, 16);
const cAF = (handle) => isClient ? window.cancelAnimationFrame(handle) : clearTimeout(handle);
//#endregion
export { cAF, rAF };
//# sourceMappingURL=raf.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"raf.mjs","names":[],"sources":["../../../../packages/utils/raf.ts"],"sourcesContent":["import { isClient } from './browser'\n\nexport const rAF = (fn: () => void) =>\n isClient\n ? window.requestAnimationFrame(fn)\n : (setTimeout(fn, 16) as unknown as number)\n\nexport const cAF = (handle: number) =>\n isClient ? window.cancelAnimationFrame(handle) : clearTimeout(handle)\n"],"mappings":";;;AAEA,MAAa,OAAO,OAClB,WACI,OAAO,sBAAsB,GAAG,GAC/B,WAAW,IAAI,GAAG;AAEzB,MAAa,OAAO,WAClB,WAAW,OAAO,qBAAqB,OAAO,GAAG,aAAa,OAAO"}
+15
View File
@@ -0,0 +1,15 @@
//#region ../../packages/utils/rand.d.ts
/**
* @deprecated Use `useId` `useIdInjection` instead
* Generate random number in range [0, 1000]
* Maybe replace with [uuid](https://www.npmjs.com/package/uuid)
*/
declare const generateId: () => number;
/**
* @deprecated
* Generating a random int in range (0, max - 1)
* @param max {number}
*/
declare const getRandomInt: (max: number) => number;
//#endregion
export { generateId, getRandomInt };
+17
View File
@@ -0,0 +1,17 @@
//#region ../../packages/utils/rand.ts
/**
* @deprecated Use `useId` `useIdInjection` instead
* Generate random number in range [0, 1000]
* Maybe replace with [uuid](https://www.npmjs.com/package/uuid)
*/
const generateId = () => Math.floor(Math.random() * 1e4);
/**
* @deprecated
* Generating a random int in range (0, max - 1)
* @param max {number}
*/
const getRandomInt = (max) => Math.floor(Math.random() * Math.floor(max));
//#endregion
export { generateId, getRandomInt };
//# sourceMappingURL=rand.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"rand.mjs","names":[],"sources":["../../../../packages/utils/rand.ts"],"sourcesContent":["/**\n * @deprecated Use `useId` `useIdInjection` instead\n * Generate random number in range [0, 1000]\n * Maybe replace with [uuid](https://www.npmjs.com/package/uuid)\n */\nexport const generateId = (): number => Math.floor(Math.random() * 10000)\n\n/**\n * @deprecated\n * Generating a random int in range (0, max - 1)\n * @param max {number}\n */\nexport const getRandomInt = (max: number) =>\n Math.floor(Math.random() * Math.floor(max))\n"],"mappings":";;;;;;AAKA,MAAa,mBAA2B,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAM;;;;;;AAOzE,MAAa,gBAAgB,QAC3B,KAAK,MAAM,KAAK,QAAQ,GAAG,KAAK,MAAM,IAAI,CAAC"}
+11
View File
@@ -0,0 +1,11 @@
import { camelize, hyphenate } from "@vue/shared";
//#region ../../packages/utils/strings.d.ts
declare const kebabCase: (str: string) => string;
/**
* fork from {@link https://github.com/sindresorhus/escape-string-regexp}
*/
declare const escapeStringRegexp: (string?: string) => string;
declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
//#endregion
export { camelize, capitalize, escapeStringRegexp, hyphenate, kebabCase };
+13
View File
@@ -0,0 +1,13 @@
import { camelize, capitalize as capitalize$1, hyphenate } from "@vue/shared";
//#region ../../packages/utils/strings.ts
const kebabCase = hyphenate;
/**
* fork from {@link https://github.com/sindresorhus/escape-string-regexp}
*/
const escapeStringRegexp = (string = "") => string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
const capitalize = (str) => capitalize$1(str);
//#endregion
export { camelize, capitalize, escapeStringRegexp, hyphenate, kebabCase };
//# sourceMappingURL=strings.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"strings.mjs","names":["toCapitalize"],"sources":["../../../../packages/utils/strings.ts"],"sourcesContent":["import { camelize, hyphenate, capitalize as toCapitalize } from '@vue/shared'\n\nexport { camelize, hyphenate }\nexport const kebabCase = hyphenate\n\n/**\n * fork from {@link https://github.com/sindresorhus/escape-string-regexp}\n */\nexport const escapeStringRegexp = (string = '') =>\n string.replace(/[|\\\\{}()[\\]^$+*?.]/g, '\\\\$&').replace(/-/g, '\\\\x2d')\n\n// NOTE: improve capitalize types. Restore previous code after the [PR](https://github.com/vuejs/core/pull/6212) merge\nexport const capitalize = <T extends string>(str: T) =>\n toCapitalize(str) as Capitalize<T>\n"],"mappings":";;;AAGA,MAAa,YAAY;;;;AAKzB,MAAa,sBAAsB,SAAS,OAC1C,OAAO,QAAQ,uBAAuB,OAAO,CAAC,QAAQ,MAAM,QAAQ;AAGtE,MAAa,cAAgC,QAC3CA,aAAa,IAAI"}
+7
View File
@@ -0,0 +1,7 @@
//#region ../../packages/utils/throttleByRaf.d.ts
declare function throttleByRaf(cb: (...args: any[]) => void): {
(...args: any[]): void;
cancel(): void;
};
//#endregion
export { throttleByRaf };
+22
View File
@@ -0,0 +1,22 @@
import { cAF, rAF } from "./raf.mjs";
//#region ../../packages/utils/throttleByRaf.ts
function throttleByRaf(cb) {
let timer = 0;
const throttle = (...args) => {
if (timer) cAF(timer);
timer = rAF(() => {
cb(...args);
timer = 0;
});
};
throttle.cancel = () => {
cAF(timer);
timer = 0;
};
return throttle;
}
//#endregion
export { throttleByRaf };
//# sourceMappingURL=throttleByRaf.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"throttleByRaf.mjs","names":[],"sources":["../../../../packages/utils/throttleByRaf.ts"],"sourcesContent":["import { cAF, rAF } from './raf'\n\nexport function throttleByRaf(cb: (...args: any[]) => void) {\n let timer = 0\n\n const throttle = (...args: any[]): void => {\n if (timer) {\n cAF(timer)\n }\n timer = rAF(() => {\n cb(...args)\n timer = 0\n })\n }\n\n throttle.cancel = () => {\n cAF(timer)\n timer = 0\n }\n\n return throttle\n}\n"],"mappings":";;;AAEA,SAAgB,cAAc,IAA8B;CAC1D,IAAI,QAAQ;CAEZ,MAAM,YAAY,GAAG,SAAsB;AACzC,MAAI,MACF,KAAI,MAAM;AAEZ,UAAQ,UAAU;AAChB,MAAG,GAAG,KAAK;AACX,WAAQ;IACR;;AAGJ,UAAS,eAAe;AACtB,MAAI,MAAM;AACV,UAAQ;;AAGV,QAAO"}
+13
View File
@@ -0,0 +1,13 @@
import { isArray, isDate, isFunction, isObject, isPlainObject, isPromise, isString, isSymbol } from "@vue/shared";
//#region ../../packages/utils/types.d.ts
declare const isUndefined: (val: any) => val is undefined;
declare const isBoolean: (val: any) => val is boolean;
declare const isNumber: (val: any) => val is number;
declare const isEmpty: (val: unknown) => boolean;
declare const isElement: (e: unknown) => e is Element;
declare const isPropAbsent: (prop: unknown) => prop is null | undefined;
declare const isStringNumber: (val: string) => boolean;
declare const isWindow: (val: unknown) => val is Window;
//#endregion
export { isArray, isBoolean, isDate, isElement, isEmpty, isFunction, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isString, isStringNumber, isSymbol, isUndefined, isWindow };
+22
View File
@@ -0,0 +1,22 @@
import { isArray, isArray as isArray$1, isDate, isFunction, isObject, isObject as isObject$1, isPlainObject, isPromise, isString, isString as isString$1, isSymbol } from "@vue/shared";
import { isNil } from "lodash-unified";
//#region ../../packages/utils/types.ts
const isUndefined = (val) => val === void 0;
const isBoolean = (val) => typeof val === "boolean";
const isNumber = (val) => typeof val === "number";
const isEmpty = (val) => !val && val !== 0 || isArray$1(val) && val.length === 0 || isObject$1(val) && !Object.keys(val).length;
const isElement = (e) => {
if (typeof Element === "undefined") return false;
return e instanceof Element;
};
const isPropAbsent = (prop) => isNil(prop);
const isStringNumber = (val) => {
if (!isString$1(val)) return false;
return !Number.isNaN(Number(val));
};
const isWindow = (val) => val === window;
//#endregion
export { isArray, isBoolean, isDate, isElement, isEmpty, isFunction, isNumber, isObject, isPlainObject, isPromise, isPropAbsent, isString, isStringNumber, isSymbol, isUndefined, isWindow };
//# sourceMappingURL=types.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.mjs","names":["isArray","isObject","isString"],"sources":["../../../../packages/utils/types.ts"],"sourcesContent":["import { isArray, isObject, isString } from '@vue/shared'\nimport { isNil } from 'lodash-unified'\n\nexport {\n isArray,\n isFunction,\n isObject,\n isString,\n isDate,\n isPromise,\n isSymbol,\n isPlainObject,\n} from '@vue/shared'\n\nexport const isUndefined = (val: any): val is undefined => val === undefined\nexport const isBoolean = (val: any): val is boolean => typeof val === 'boolean'\nexport const isNumber = (val: any): val is number => typeof val === 'number'\n\nexport const isEmpty = (val: unknown) =>\n (!val && val !== 0) ||\n (isArray(val) && val.length === 0) ||\n (isObject(val) && !Object.keys(val).length)\n\nexport const isElement = (e: unknown): e is Element => {\n if (typeof Element === 'undefined') return false\n return e instanceof Element\n}\n\nexport const isPropAbsent = (prop: unknown): prop is null | undefined =>\n isNil(prop)\n\nexport const isStringNumber = (val: string): boolean => {\n if (!isString(val)) {\n return false\n }\n return !Number.isNaN(Number(val))\n}\n\nexport const isWindow = (val: unknown): val is Window => val === window\n"],"mappings":";;;;AAcA,MAAa,eAAe,QAA+B,QAAQ;AACnE,MAAa,aAAa,QAA6B,OAAO,QAAQ;AACtE,MAAa,YAAY,QAA4B,OAAO,QAAQ;AAEpE,MAAa,WAAW,QACrB,CAAC,OAAO,QAAQ,KAChBA,UAAQ,IAAI,IAAI,IAAI,WAAW,KAC/BC,WAAS,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC;AAEtC,MAAa,aAAa,MAA6B;AACrD,KAAI,OAAO,YAAY,YAAa,QAAO;AAC3C,QAAO,aAAa;;AAGtB,MAAa,gBAAgB,SAC3B,MAAM,KAAK;AAEb,MAAa,kBAAkB,QAAyB;AACtD,KAAI,CAACC,WAAS,IAAI,CAChB,QAAO;AAET,QAAO,CAAC,OAAO,MAAM,OAAO,IAAI,CAAC;;AAGnC,MAAa,YAAY,QAAgC,QAAQ"}
+90
View File
@@ -0,0 +1,90 @@
import * as CSS from "csstype";
//#region ../../packages/utils/typescript.d.ts
declare const mutable: <T extends readonly any[] | Record<string, unknown>>(val: T) => Mutable<typeof val>;
type Mutable<T> = { -readonly [P in keyof T]: T[P] };
type HTMLElementCustomized<T> = HTMLElement & T;
/**
* @deprecated stop to use null
* @see {@link https://github.com/sindresorhus/meta/discussions/7}
*/
type Nullable<T> = T | null;
type Arrayable<T> = T | T[];
type Awaitable<T> = Promise<T> | T;
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
type BrowserNativeObject = Date | FileList | File | Blob | RegExp;
/**
* Check whether it is tuple
*
* 检查是否为元组
*
* @example
* IsTuple<[1, 2, 3]> => true
* IsTuple<Array[number]> => false
*/
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
/**
* Array method key
*
* 数组方法键
*/
type ArrayMethodKey = keyof any[];
/**
* Tuple index key
*
* 元组下标键
*
* @example
* TupleKey<[1, 2, 3]> => '0' | '1' | '2'
*/
type TupleKey<T extends ReadonlyArray<any>> = Exclude<keyof T, ArrayMethodKey>;
/**
* Array index key
*
* 数组下标键
*/
type ArrayKey = number;
/**
* Helper type for recursively constructing paths through a type
*
* 用于通过一个类型递归构建路径的辅助类型
*/
type PathImpl<K extends string | number, V> = V extends Primitive | BrowserNativeObject ? `${K}` : `${K}` | `${K}.${Path<V>}`;
/**
* Type which collects all paths through a type
*
* 通过一个类型收集所有路径的类型
*
* @see {@link FieldPath}
*/
type Path<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? { [K in TupleKey<T>]-?: PathImpl<Exclude<K, symbol>, T[K]> }[TupleKey<T>] : PathImpl<ArrayKey, V> : { [K in keyof T]-?: PathImpl<Exclude<K, symbol>, T[K]> }[keyof T];
/**
* Type which collects all paths through a type
*
* 通过一个类型收集所有路径的类型
*
* @example
* FieldPath<{ 1: number; a: number; b: string; c: { d: number; e: string }; f: [{ value: string }]; g: { value: string }[]; h: Date; i: FileList; j: File; k: Blob; l: RegExp }> => '1' | 'a' | 'b' | 'c' | 'f' | 'g' | 'c.d' | 'c.e' | 'f.0' | 'f.0.value' | 'g.number' | 'g.number.value' | 'h' | 'i' | 'j' | 'k' | 'l'
*/
type FieldPath<T> = T extends object ? Path<T> : never;
/**
* csstype 是 vue的依赖,因此,直接从vue中导入CSSProperties会导致ts类型解析错误,参考 https://github.com/pnpm/pnpm/issues/7453,因此,我们直接安装csstype,并从csstype中导入CSSProperties
*
* csstype is a dependency of vue, so importing CSSProperties directly from vue will cause ts type parsing errors, see https://github.com/pnpm/pnpm/issues/7453. Therefore, we directly install csstype and import CSSProperties from csstype.
*/
interface CSSProperties extends CSS.Properties<string | number>, CSS.PropertiesHyphen<string | number> {
/**
* The index signature was removed to enable closed typing for style
* using CSSType. You're able to use type assertion or module augmentation
* to add properties or an index signature of your own.
*
* For examples and more information, visit:
* https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
*/
[v: `--${string}`]: string | number | undefined;
}
type ObjectFit = CSSProperties['objectFit'];
type ZIndexType = CSSProperties['zIndex'];
type AlignItems = CSSProperties['alignItems'];
//#endregion
export { AlignItems, Arrayable, Awaitable, CSSProperties, FieldPath, HTMLElementCustomized, Mutable, Nullable, ObjectFit, ZIndexType, mutable };
+6
View File
@@ -0,0 +1,6 @@
//#region ../../packages/utils/typescript.ts
const mutable = (val) => val;
//#endregion
export { mutable };
//# sourceMappingURL=typescript.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"typescript.mjs","names":[],"sources":["../../../../packages/utils/typescript.ts"],"sourcesContent":["import type * as CSS from 'csstype'\n\nexport const mutable = <T extends readonly any[] | Record<string, unknown>>(\n val: T\n) => val as Mutable<typeof val>\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] }\n\nexport type HTMLElementCustomized<T> = HTMLElement & T\n\n/**\n * @deprecated stop to use null\n * @see {@link https://github.com/sindresorhus/meta/discussions/7}\n */\nexport type Nullable<T> = T | null\n\nexport type Arrayable<T> = T | T[]\nexport type Awaitable<T> = Promise<T> | T\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint\ntype BrowserNativeObject = Date | FileList | File | Blob | RegExp\n\n/**\n * Check whether it is tuple\n *\n * 检查是否为元组\n *\n * @example\n * IsTuple<[1, 2, 3]> => true\n * IsTuple<Array[number]> => false\n */\ntype IsTuple<T extends ReadonlyArray<any>> = number extends T['length']\n ? false\n : true\n\n/**\n * Array method key\n *\n * 数组方法键\n */\ntype ArrayMethodKey = keyof any[]\n\n/**\n * Tuple index key\n *\n * 元组下标键\n *\n * @example\n * TupleKey<[1, 2, 3]> => '0' | '1' | '2'\n */\ntype TupleKey<T extends ReadonlyArray<any>> = Exclude<keyof T, ArrayMethodKey>\n\n/**\n * Array index key\n *\n * 数组下标键\n */\ntype ArrayKey = number\n\n/**\n * Helper type for recursively constructing paths through a type\n *\n * 用于通过一个类型递归构建路径的辅助类型\n */\ntype PathImpl<K extends string | number, V> = V extends\n | Primitive\n | BrowserNativeObject\n ? `${K}`\n : `${K}` | `${K}.${Path<V>}`\n\n/**\n * Type which collects all paths through a type\n *\n * 通过一个类型收集所有路径的类型\n *\n * @see {@link FieldPath}\n */\ntype Path<T> =\n T extends ReadonlyArray<infer V>\n ? IsTuple<T> extends true\n ? {\n [K in TupleKey<T>]-?: PathImpl<Exclude<K, symbol>, T[K]>\n }[TupleKey<T>] // tuple\n : PathImpl<ArrayKey, V> // array\n : {\n [K in keyof T]-?: PathImpl<Exclude<K, symbol>, T[K]>\n }[keyof T] // object\n\n/**\n * Type which collects all paths through a type\n *\n * 通过一个类型收集所有路径的类型\n *\n * @example\n * FieldPath<{ 1: number; a: number; b: string; c: { d: number; e: string }; f: [{ value: string }]; g: { value: string }[]; h: Date; i: FileList; j: File; k: Blob; l: RegExp }> => '1' | 'a' | 'b' | 'c' | 'f' | 'g' | 'c.d' | 'c.e' | 'f.0' | 'f.0.value' | 'g.number' | 'g.number.value' | 'h' | 'i' | 'j' | 'k' | 'l'\n */\nexport type FieldPath<T> = T extends object ? Path<T> : never\n\n/**\n * csstype 是 vue的依赖,因此,直接从vue中导入CSSProperties会导致ts类型解析错误,参考 https://github.com/pnpm/pnpm/issues/7453,因此,我们直接安装csstype,并从csstype中导入CSSProperties\n *\n * csstype is a dependency of vue, so importing CSSProperties directly from vue will cause ts type parsing errors, see https://github.com/pnpm/pnpm/issues/7453. Therefore, we directly install csstype and import CSSProperties from csstype.\n */\nexport interface CSSProperties\n extends\n CSS.Properties<string | number>,\n CSS.PropertiesHyphen<string | number> {\n /**\n * The index signature was removed to enable closed typing for style\n * using CSSType. You're able to use type assertion or module augmentation\n * to add properties or an index signature of your own.\n *\n * For examples and more information, visit:\n * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors\n */\n [v: `--${string}`]: string | number | undefined\n}\n\nexport type ObjectFit = CSSProperties['objectFit']\n\nexport type ZIndexType = CSSProperties['zIndex']\n\nexport type AlignItems = CSSProperties['alignItems']\n"],"mappings":";AAEA,MAAa,WACX,QACG"}
+6
View File
@@ -0,0 +1,6 @@
//#region ../../packages/utils/vue/global-node.d.ts
declare function createGlobalNode(id?: string): HTMLDivElement;
declare function removeGlobalNode(el: HTMLElement): void;
declare function changeGlobalNodesTarget(el: HTMLElement): void;
//#endregion
export { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode };
+29
View File
@@ -0,0 +1,29 @@
import { isClient } from "../browser.mjs";
//#region ../../packages/utils/vue/global-node.ts
const globalNodes = [];
let target = !isClient ? void 0 : document.body;
function createGlobalNode(id) {
const el = document.createElement("div");
if (id !== void 0) el.setAttribute("id", id);
if (target) {
target.appendChild(el);
globalNodes.push(el);
}
return el;
}
function removeGlobalNode(el) {
globalNodes.splice(globalNodes.indexOf(el), 1);
el.remove();
}
function changeGlobalNodesTarget(el) {
if (el === target) return;
target = el;
globalNodes.forEach((el) => {
if (target && !el.contains(target)) target.appendChild(el);
});
}
//#endregion
export { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode };
//# sourceMappingURL=global-node.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"global-node.mjs","names":[],"sources":["../../../../../packages/utils/vue/global-node.ts"],"sourcesContent":["import { isClient } from '../browser'\n\nconst globalNodes: HTMLElement[] = []\nlet target: HTMLElement | undefined = !isClient ? undefined : document.body\n\nexport function createGlobalNode(id?: string) {\n const el = document.createElement('div')\n if (id !== undefined) {\n el.setAttribute('id', id)\n }\n\n if (target) {\n target.appendChild(el)\n globalNodes.push(el)\n }\n\n return el\n}\n\nexport function removeGlobalNode(el: HTMLElement) {\n globalNodes.splice(globalNodes.indexOf(el), 1)\n el.remove()\n}\n\nexport function changeGlobalNodesTarget(el: HTMLElement) {\n if (el === target) return\n\n target = el\n globalNodes.forEach((el) => {\n if (target && !el.contains(target)) {\n target.appendChild(el)\n }\n })\n}\n"],"mappings":";;;AAEA,MAAM,cAA6B,EAAE;AACrC,IAAI,SAAkC,CAAC,WAAW,SAAY,SAAS;AAEvE,SAAgB,iBAAiB,IAAa;CAC5C,MAAM,KAAK,SAAS,cAAc,MAAM;AACxC,KAAI,OAAO,OACT,IAAG,aAAa,MAAM,GAAG;AAG3B,KAAI,QAAQ;AACV,SAAO,YAAY,GAAG;AACtB,cAAY,KAAK,GAAG;;AAGtB,QAAO;;AAGT,SAAgB,iBAAiB,IAAiB;AAChD,aAAY,OAAO,YAAY,QAAQ,GAAG,EAAE,EAAE;AAC9C,IAAG,QAAQ;;AAGb,SAAgB,wBAAwB,IAAiB;AACvD,KAAI,OAAO,OAAQ;AAEnB,UAAS;AACT,aAAY,SAAS,OAAO;AAC1B,MAAI,UAAU,CAAC,GAAG,SAAS,OAAO,CAChC,QAAO,YAAY,GAAG;GAExB"}
+32
View File
@@ -0,0 +1,32 @@
import * as vue from "vue";
import { Component } from "vue";
import { Loading } from "@element-plus/icons-vue";
//#region ../../packages/utils/vue/icon.d.ts
type IconPropType = string | Component;
declare const iconPropType: vue.PropType<string | Component>;
declare const CloseComponents: {
Close: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
};
declare const TypeComponents: {
Close: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
SuccessFilled: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
InfoFilled: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
WarningFilled: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
CircleCloseFilled: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
};
declare const TypeComponentsMap: {
primary: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
success: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
warning: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
error: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
info: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
};
declare const ValidateComponentsMap: {
validating: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
success: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
error: vue.DefineComponent<{}, void, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
};
type IconComponent = typeof Loading;
//#endregion
export { CloseComponents, IconComponent, IconPropType, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType };
+33
View File
@@ -0,0 +1,33 @@
import { definePropType } from "./props/runtime.mjs";
import { CircleCheck, CircleClose, CircleCloseFilled, Close, InfoFilled, Loading, SuccessFilled, WarningFilled } from "@element-plus/icons-vue";
//#region ../../packages/utils/vue/icon.ts
const iconPropType = definePropType([
String,
Object,
Function
]);
const CloseComponents = { Close };
const TypeComponents = {
Close,
SuccessFilled,
InfoFilled,
WarningFilled,
CircleCloseFilled
};
const TypeComponentsMap = {
primary: InfoFilled,
success: SuccessFilled,
warning: WarningFilled,
error: CircleCloseFilled,
info: InfoFilled
};
const ValidateComponentsMap = {
validating: Loading,
success: CircleCheck,
error: CircleClose
};
//#endregion
export { CloseComponents, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType };
//# sourceMappingURL=icon.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"icon.mjs","names":[],"sources":["../../../../../packages/utils/vue/icon.ts"],"sourcesContent":["import {\n CircleCheck,\n CircleClose,\n CircleCloseFilled,\n Close,\n InfoFilled,\n Loading,\n SuccessFilled,\n WarningFilled,\n} from '@element-plus/icons-vue'\nimport { definePropType } from './props'\n\nimport type { Component } from 'vue'\n\nexport type IconPropType = string | Component\n\nexport const iconPropType = definePropType<string | Component>([\n String,\n Object,\n Function,\n])\n\nexport const CloseComponents = {\n Close,\n}\n\nexport const TypeComponents = {\n Close,\n SuccessFilled,\n InfoFilled,\n WarningFilled,\n CircleCloseFilled,\n}\n\nexport const TypeComponentsMap = {\n primary: InfoFilled,\n success: SuccessFilled,\n warning: WarningFilled,\n error: CircleCloseFilled,\n info: InfoFilled,\n}\n\nexport const ValidateComponentsMap = {\n validating: Loading,\n success: CircleCheck,\n error: CircleClose,\n}\n\n// All icon components have the same type, so we can pick any one of them to get the type\nexport type IconComponent = typeof Loading\n"],"mappings":";;;;AAgBA,MAAa,eAAe,eAAmC;CAC7D;CACA;CACA;CACD,CAAC;AAEF,MAAa,kBAAkB,EAC7B,OACD;AAED,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,oBAAoB;CAC/B,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;CACP,MAAM;CACP;AAED,MAAa,wBAAwB;CACnC,YAAY;CACZ,SAAS;CACT,OAAO;CACR"}
+13
View File
@@ -0,0 +1,13 @@
import { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode } from "./global-node.js";
import { CloseComponents, IconComponent, IconPropType, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType } from "./icon.js";
import { EmitFn, SFCInstallWithContext, SFCWithInstall, SFCWithPropsDefaultsSetter } from "./typescript.js";
import { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter } from "./install.js";
import { IfNever, IfUnknown, UnknownToNever, Writable, WritableArray } from "./props/util.js";
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./props/runtime.js";
import { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, IfEpProp, IfNativePropType, NativePropType, ResolvePropType } from "./props/types.js";
import "./props/index.js";
import { composeRefs } from "./refs.js";
import { getComponentSize } from "./size.js";
import { isValidComponentSize, isValidDatePickType } from "./validator.js";
import { FlattenVNodes, PatchFlags, RawSlots, VNodeChildAtom, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf } from "./vnode.js";
export { CloseComponents, EmitFn, EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, FlattenVNodes, IconComponent, IconPropType, IfEpProp, IfNativePropType, IfNever, IfUnknown, NativePropType, PatchFlags, RawSlots, ResolvePropType, SFCInstallWithContext, SFCWithInstall, SFCWithPropsDefaultsSetter, TypeComponents, TypeComponentsMap, UnknownToNever, VNodeChildAtom, ValidateComponentsMap, Writable, WritableArray, buildProp, buildProps, changeGlobalNodesTarget, composeRefs, createGlobalNode, definePropType, epPropKey, flattedChildren, getComponentSize, getFirstValidNode, getNormalizedProps, iconPropType, isComment, isEpProp, isFragment, isTemplate, isText, isValidComponentSize, isValidDatePickType, isValidElementNode, removeGlobalNode, renderBlock, renderIf, withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
+10
View File
@@ -0,0 +1,10 @@
import { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode } from "./global-node.mjs";
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./props/runtime.mjs";
import { CloseComponents, TypeComponents, TypeComponentsMap, ValidateComponentsMap, iconPropType } from "./icon.mjs";
import { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter } from "./install.mjs";
import { composeRefs } from "./refs.mjs";
import { getComponentSize } from "./size.mjs";
import { isValidComponentSize, isValidDatePickType } from "./validator.mjs";
import { PatchFlags, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf } from "./vnode.mjs";
export { CloseComponents, PatchFlags, TypeComponents, TypeComponentsMap, ValidateComponentsMap, buildProp, buildProps, changeGlobalNodesTarget, composeRefs, createGlobalNode, definePropType, epPropKey, flattedChildren, getComponentSize, getFirstValidNode, getNormalizedProps, iconPropType, isComment, isEpProp, isFragment, isTemplate, isText, isValidComponentSize, isValidDatePickType, isValidElementNode, removeGlobalNode, renderBlock, renderIf, withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
+11
View File
@@ -0,0 +1,11 @@
import { SFCInstallWithContext, SFCWithInstall } from "./typescript.js";
import { Directive } from "vue";
//#region ../../packages/utils/vue/install.d.ts
declare const withPropsDefaultsSetter: (target: any) => void;
declare const withInstall: <T, E extends Record<string, any>>(main: T, extra?: E) => SFCWithInstall<T> & E;
declare const withInstallFunction: <T>(fn: T, name: string) => SFCInstallWithContext<T>;
declare const withInstallDirective: <T extends Directive>(directive: T, name: string) => SFCWithInstall<T>;
declare const withNoopInstall: <T>(component: T) => SFCWithInstall<T>;
//#endregion
export { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
+58
View File
@@ -0,0 +1,58 @@
import { NOOP } from "../functions.mjs";
import { hasOwn, isArray } from "@vue/shared";
import { fromPairs, isPlainObject } from "lodash-unified";
//#region ../../packages/utils/vue/install.ts
const withPropsDefaultsSetter = (target) => {
const _p = target.props;
const props = isArray(_p) ? fromPairs(_p.map((key) => [key, {}])) : _p;
target.setPropsDefaults = (defaults) => {
if (!props) return;
for (const [key, value] of Object.entries(defaults)) {
const prop = props[key];
if (!hasOwn(props, key)) continue;
if (isPlainObject(prop)) {
props[key] = {
...prop,
default: value
};
continue;
}
props[key] = {
type: prop,
default: value
};
}
target.props = props;
};
};
const withInstall = (main, extra) => {
main.install = (app) => {
for (const comp of [main, ...Object.values(extra ?? {})]) app.component(comp.name, comp);
};
if (extra) for (const [key, comp] of Object.entries(extra)) main[key] = comp;
withPropsDefaultsSetter(main);
return main;
};
const withInstallFunction = (fn, name) => {
fn.install = (app) => {
fn._context = app._context;
app.config.globalProperties[name] = fn;
};
return fn;
};
const withInstallDirective = (directive, name) => {
directive.install = (app) => {
app.directive(name, directive);
};
return directive;
};
const withNoopInstall = (component) => {
component.install = NOOP;
withPropsDefaultsSetter(component);
return component;
};
//#endregion
export { withInstall, withInstallDirective, withInstallFunction, withNoopInstall, withPropsDefaultsSetter };
//# sourceMappingURL=install.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"install.mjs","names":[],"sources":["../../../../../packages/utils/vue/install.ts"],"sourcesContent":["import { hasOwn, isArray } from '@vue/shared'\nimport { fromPairs, isPlainObject } from 'lodash-unified'\nimport { NOOP } from '../functions'\n\nimport type { App, Directive } from 'vue'\nimport type { SFCInstallWithContext, SFCWithInstall } from './typescript'\n\nexport const withPropsDefaultsSetter = (target: any) => {\n const _p = target.props\n const props = isArray(_p) ? fromPairs(_p.map((key) => [key, {}])) : _p\n\n target.setPropsDefaults = (defaults: Record<string, any>) => {\n if (!props) {\n return\n }\n\n for (const [key, value] of Object.entries(defaults)) {\n const prop = props[key]\n\n if (!hasOwn(props, key)) {\n continue\n }\n\n if (isPlainObject(prop)) {\n // e.g. { type: String }\n props[key] = {\n ...prop,\n default: value,\n }\n continue\n }\n\n props[key] = {\n type: prop,\n default: value,\n }\n }\n\n target.props = props\n }\n}\n\nexport const withInstall = <T, E extends Record<string, any>>(\n main: T,\n extra?: E\n) => {\n ;(main as SFCWithInstall<T>).install = (app): void => {\n for (const comp of [main, ...Object.values(extra ?? {})]) {\n app.component(comp.name, comp)\n }\n }\n\n if (extra) {\n for (const [key, comp] of Object.entries(extra)) {\n ;(main as any)[key] = comp\n }\n }\n withPropsDefaultsSetter(main)\n return main as SFCWithInstall<T> & E\n}\n\nexport const withInstallFunction = <T>(fn: T, name: string) => {\n ;(fn as SFCWithInstall<T>).install = (app: App) => {\n ;(fn as SFCInstallWithContext<T>)._context = app._context\n app.config.globalProperties[name] = fn\n }\n\n return fn as SFCInstallWithContext<T>\n}\n\nexport const withInstallDirective = <T extends Directive>(\n directive: T,\n name: string\n) => {\n ;(directive as SFCWithInstall<T>).install = (app: App): void => {\n app.directive(name, directive)\n }\n\n return directive as SFCWithInstall<T>\n}\n\nexport const withNoopInstall = <T>(component: T) => {\n ;(component as SFCWithInstall<T>).install = NOOP\n withPropsDefaultsSetter(component)\n return component as SFCWithInstall<T>\n}\n"],"mappings":";;;;;AAOA,MAAa,2BAA2B,WAAgB;CACtD,MAAM,KAAK,OAAO;CAClB,MAAM,QAAQ,QAAQ,GAAG,GAAG,UAAU,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG;AAEpE,QAAO,oBAAoB,aAAkC;AAC3D,MAAI,CAAC,MACH;AAGF,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,EAAE;GACnD,MAAM,OAAO,MAAM;AAEnB,OAAI,CAAC,OAAO,OAAO,IAAI,CACrB;AAGF,OAAI,cAAc,KAAK,EAAE;AAEvB,UAAM,OAAO;KACX,GAAG;KACH,SAAS;KACV;AACD;;AAGF,SAAM,OAAO;IACX,MAAM;IACN,SAAS;IACV;;AAGH,SAAO,QAAQ;;;AAInB,MAAa,eACX,MACA,UACG;AACF,CAAC,KAA2B,WAAW,QAAc;AACpD,OAAK,MAAM,QAAQ,CAAC,MAAM,GAAG,OAAO,OAAO,SAAS,EAAE,CAAC,CAAC,CACtD,KAAI,UAAU,KAAK,MAAM,KAAK;;AAIlC,KAAI,MACF,MAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,CAC5C,CAAC,KAAa,OAAO;AAG1B,yBAAwB,KAAK;AAC7B,QAAO;;AAGT,MAAa,uBAA0B,IAAO,SAAiB;AAC5D,CAAC,GAAyB,WAAW,QAAa;AAChD,EAAC,GAAgC,WAAW,IAAI;AACjD,MAAI,OAAO,iBAAiB,QAAQ;;AAGtC,QAAO;;AAGT,MAAa,wBACX,WACA,SACG;AACF,CAAC,UAAgC,WAAW,QAAmB;AAC9D,MAAI,UAAU,MAAM,UAAU;;AAGhC,QAAO;;AAGT,MAAa,mBAAsB,cAAiB;AACjD,CAAC,UAAgC,UAAU;AAC5C,yBAAwB,UAAU;AAClC,QAAO"}
+4
View File
@@ -0,0 +1,4 @@
import { IfNever, IfUnknown, UnknownToNever, Writable, WritableArray } from "./util.js";
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./runtime.js";
import { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, IfEpProp, IfNativePropType, NativePropType, ResolvePropType } from "./types.js";
export { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, IfEpProp, IfNativePropType, IfNever, IfUnknown, NativePropType, ResolvePropType, UnknownToNever, Writable, WritableArray, buildProp, buildProps, definePropType, epPropKey, isEpProp };
+3
View File
@@ -0,0 +1,3 @@
import { buildProp, buildProps, definePropType, epPropKey, isEpProp } from "./runtime.mjs";
export { buildProp, buildProps, definePropType, epPropKey, isEpProp };
+33
View File
@@ -0,0 +1,33 @@
import { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropMergeType, IfEpProp, IfNativePropType, NativePropType } from "./types.js";
import { PropType } from "vue";
//#region ../../packages/utils/vue/props/runtime.d.ts
declare const epPropKey = "__epPropKey";
declare const definePropType: <T>(val: any) => PropType<T>;
declare const isEpProp: (val: unknown) => val is EpProp<any, any, any>;
/**
* @description Build prop. It can better optimize prop types
* @description 生成 prop,能更好地优化类型
* @example
// limited options
// the type will be PropType<'light' | 'dark'>
buildProp({
type: String,
values: ['light', 'dark'],
} as const)
* @example
// limited options and other types
// the type will be PropType<'small' | 'large' | number>
buildProp({
type: [String, Number],
values: ['small', 'large'],
validator: (val: unknown): val is number => typeof val === 'number',
} as const)
@link see more: https://github.com/element-plus/element-plus/pull/3341
*/
declare const buildProp: <Type = never, Value = never, Validator = never, Default extends EpPropMergeType<Type, Value, Validator> = never, Required extends boolean = false>(prop: EpPropInput<Type, Value, Validator, Default, Required>, key?: string) => EpPropFinalized<Type, Value, Validator, Default, Required>;
declare const buildProps: <Props extends Record<string, {
[epPropKey]: true;
} | NativePropType | EpPropInput<any, any, any, any, any>>>(props: Props) => { [K in keyof Props]: IfEpProp<Props[K], Props[K], IfNativePropType<Props[K], Props[K], EpPropConvert<Props[K]>>> };
//#endregion
export { buildProp, buildProps, definePropType, epPropKey, isEpProp };
+60
View File
@@ -0,0 +1,60 @@
import { isObject } from "../../types.mjs";
import { hasOwn } from "../../objects.mjs";
import { fromPairs } from "lodash-unified";
import { warn } from "vue";
//#region ../../packages/utils/vue/props/runtime.ts
const epPropKey = "__epPropKey";
const definePropType = (val) => val;
const isEpProp = (val) => isObject(val) && !!val[epPropKey];
/**
* @description Build prop. It can better optimize prop types
* @description 生成 prop,能更好地优化类型
* @example
// limited options
// the type will be PropType<'light' | 'dark'>
buildProp({
type: String,
values: ['light', 'dark'],
} as const)
* @example
// limited options and other types
// the type will be PropType<'small' | 'large' | number>
buildProp({
type: [String, Number],
values: ['small', 'large'],
validator: (val: unknown): val is number => typeof val === 'number',
} as const)
@link see more: https://github.com/element-plus/element-plus/pull/3341
*/
const buildProp = (prop, key) => {
if (!isObject(prop) || isEpProp(prop)) return prop;
const { values, required, default: defaultValue, type, validator } = prop;
const epProp = {
type,
required: !!required,
validator: values || validator ? (val) => {
let valid = false;
let allowedValues = [];
if (values) {
allowedValues = Array.from(values);
if (hasOwn(prop, "default")) allowedValues.push(defaultValue);
valid ||= allowedValues.includes(val);
}
if (validator) valid ||= validator(val);
if (!valid && allowedValues.length > 0) {
const allowValuesText = [...new Set(allowedValues)].map((value) => JSON.stringify(value)).join(", ");
warn(`Invalid prop: validation failed${key ? ` for prop "${key}"` : ""}. Expected one of [${allowValuesText}], got value ${JSON.stringify(val)}.`);
}
return valid;
} : void 0,
[epPropKey]: true
};
if (hasOwn(prop, "default")) epProp.default = defaultValue;
return epProp;
};
const buildProps = (props) => fromPairs(Object.entries(props).map(([key, option]) => [key, buildProp(option, key)]));
//#endregion
export { buildProp, buildProps, definePropType, epPropKey, isEpProp };
//# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../../../packages/utils/vue/props/runtime.ts"],"sourcesContent":["import { warn } from 'vue'\nimport { fromPairs } from 'lodash-unified'\nimport { isObject } from '../../types'\nimport { hasOwn } from '../../objects'\n\nimport type { PropType } from 'vue'\nimport type {\n EpProp,\n EpPropConvert,\n EpPropFinalized,\n EpPropInput,\n EpPropMergeType,\n IfEpProp,\n IfNativePropType,\n NativePropType,\n} from './types'\n\nexport const epPropKey = '__epPropKey'\n\nexport const definePropType = <T>(val: any): PropType<T> => val\n\nexport const isEpProp = (val: unknown): val is EpProp<any, any, any> =>\n isObject(val) && !!(val as any)[epPropKey]\n\n/**\n * @description Build prop. It can better optimize prop types\n * @description 生成 prop,能更好地优化类型\n * @example\n // limited options\n // the type will be PropType<'light' | 'dark'>\n buildProp({\n type: String,\n values: ['light', 'dark'],\n } as const)\n * @example\n // limited options and other types\n // the type will be PropType<'small' | 'large' | number>\n buildProp({\n type: [String, Number],\n values: ['small', 'large'],\n validator: (val: unknown): val is number => typeof val === 'number',\n } as const)\n @link see more: https://github.com/element-plus/element-plus/pull/3341\n */\nexport const buildProp = <\n Type = never,\n Value = never,\n Validator = never,\n Default extends EpPropMergeType<Type, Value, Validator> = never,\n Required extends boolean = false,\n>(\n prop: EpPropInput<Type, Value, Validator, Default, Required>,\n key?: string\n): EpPropFinalized<Type, Value, Validator, Default, Required> => {\n // filter native prop type and nested prop, e.g `null`, `undefined` (from `buildProps`)\n if (!isObject(prop) || isEpProp(prop)) return prop as any\n\n const { values, required, default: defaultValue, type, validator } = prop\n\n const _validator =\n values || validator\n ? (val: unknown) => {\n let valid = false\n let allowedValues: unknown[] = []\n\n if (values) {\n allowedValues = Array.from(values)\n if (hasOwn(prop, 'default')) {\n allowedValues.push(defaultValue)\n }\n valid ||= allowedValues.includes(val)\n }\n if (validator) valid ||= validator(val)\n\n if (!valid && allowedValues.length > 0) {\n const allowValuesText = [...new Set(allowedValues)]\n .map((value) => JSON.stringify(value))\n .join(', ')\n warn(\n `Invalid prop: validation failed${\n key ? ` for prop \"${key}\"` : ''\n }. Expected one of [${allowValuesText}], got value ${JSON.stringify(\n val\n )}.`\n )\n }\n return valid\n }\n : undefined\n\n const epProp: any = {\n type,\n required: !!required,\n validator: _validator,\n [epPropKey]: true,\n }\n if (hasOwn(prop, 'default')) epProp.default = defaultValue\n return epProp\n}\n\nexport const buildProps = <\n Props extends Record<\n string,\n | { [epPropKey]: true }\n | NativePropType\n | EpPropInput<any, any, any, any, any>\n >,\n>(\n props: Props\n): {\n [K in keyof Props]: IfEpProp<\n Props[K],\n Props[K],\n IfNativePropType<Props[K], Props[K], EpPropConvert<Props[K]>>\n >\n} =>\n fromPairs(\n Object.entries(props).map(([key, option]) => [\n key,\n buildProp(option as any, key),\n ])\n ) as any\n"],"mappings":";;;;;;AAiBA,MAAa,YAAY;AAEzB,MAAa,kBAAqB,QAA0B;AAE5D,MAAa,YAAY,QACvB,SAAS,IAAI,IAAI,CAAC,CAAE,IAAY;;;;;;;;;;;;;;;;;;;;;AAsBlC,MAAa,aAOX,MACA,QAC+D;AAE/D,KAAI,CAAC,SAAS,KAAK,IAAI,SAAS,KAAK,CAAE,QAAO;CAE9C,MAAM,EAAE,QAAQ,UAAU,SAAS,cAAc,MAAM,cAAc;CAiCrE,MAAM,SAAc;EAClB;EACA,UAAU,CAAC,CAAC;EACZ,WAjCA,UAAU,aACL,QAAiB;GAChB,IAAI,QAAQ;GACZ,IAAI,gBAA2B,EAAE;AAEjC,OAAI,QAAQ;AACV,oBAAgB,MAAM,KAAK,OAAO;AAClC,QAAI,OAAO,MAAM,UAAU,CACzB,eAAc,KAAK,aAAa;AAElC,cAAU,cAAc,SAAS,IAAI;;AAEvC,OAAI,UAAW,WAAU,UAAU,IAAI;AAEvC,OAAI,CAAC,SAAS,cAAc,SAAS,GAAG;IACtC,MAAM,kBAAkB,CAAC,GAAG,IAAI,IAAI,cAAc,CAAC,CAChD,KAAK,UAAU,KAAK,UAAU,MAAM,CAAC,CACrC,KAAK,KAAK;AACb,SACE,kCACE,MAAM,cAAc,IAAI,KAAK,GAC9B,qBAAqB,gBAAgB,eAAe,KAAK,UACxD,IACD,CAAC,GACH;;AAEH,UAAO;MAET;GAMH,YAAY;EACd;AACD,KAAI,OAAO,MAAM,UAAU,CAAE,QAAO,UAAU;AAC9C,QAAO;;AAGT,MAAa,cAQX,UAQA,UACE,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,YAAY,CAC3C,KACA,UAAU,QAAe,IAAI,CAC9B,CAAC,CACH"}
+123
View File
@@ -0,0 +1,123 @@
import { IfNever, UnknownToNever, WritableArray } from "./util.js";
import { epPropKey } from "./runtime.js";
import { ExtractPropTypes, PropType } from "vue";
//#region ../../packages/utils/vue/props/types.d.ts
type Value<T> = T[keyof T];
/**
* Extract the type of a single prop
*
* 提取单个 prop 的参数类型
*
* @example
* ExtractPropType<{ type: StringConstructor }> => string | undefined
* ExtractPropType<{ type: StringConstructor, required: true }> => string
* ExtractPropType<{ type: BooleanConstructor }> => boolean
*/
type ExtractPropType<T extends object> = Value<ExtractPropTypes<{
key: T;
}>>;
/**
* Extracts types via `ExtractPropTypes`, accepting `PropType<T>`, `XXXConstructor`, `never`...
*
* 通过 `ExtractPropTypes` 提取类型,接受 `PropType<T>`、`XXXConstructor`、`never`...
*
* @example
* ResolvePropType<BooleanConstructor> => boolean
* ResolvePropType<PropType<T>> => T
**/
type ResolvePropType<T> = IfNever<T, never, ExtractPropType<{
type: WritableArray<T>;
required: true;
}>>;
/**
* Merge Type, Value, Validator types
* 合并 Type、Value、Validator 的类型
*
* @example
* EpPropMergeType<StringConstructor, '1', 1> => 1 | "1" // ignores StringConstructor
* EpPropMergeType<StringConstructor, never, number> => string | number
*/
type EpPropMergeType<Type, Value, Validator> = IfNever<UnknownToNever<Value>, ResolvePropType<Type>, never> | UnknownToNever<Value> | UnknownToNever<Validator>;
/**
* Handling default values for input (constraints)
*
* 处理输入参数的默认值(约束)
*/
type EpPropInputDefault<Required extends boolean, Default> = Required extends true ? never : Default extends Record<string, unknown> | Array<any> ? () => Default : (() => Default) | Default;
/**
* Native prop types, e.g: `BooleanConstructor`, `StringConstructor`, `null`, `undefined`, etc.
*
* 原生 prop `类型,BooleanConstructor`、`StringConstructor`、`null`、`undefined` 等
*/
type NativePropType = ((...args: any) => any) | {
new (...args: any): any;
} | undefined | null;
type IfNativePropType<T, Y, N> = [T] extends [NativePropType] ? Y : N;
/**
* input prop `buildProp` or `buildProps` (constraints)
*
* prop 输入参数(约束)
*
* @example
* EpPropInput<StringConstructor, 'a', never, never, true>
* ⬇️
* {
type?: StringConstructor | undefined;
required?: true | undefined;
values?: readonly "a"[] | undefined;
validator?: ((val: any) => boolean) | ((val: any) => val is never) | undefined;
default?: undefined;
}
*/
type EpPropInput<Type, Value, Validator, Default extends EpPropMergeType<Type, Value, Validator>, Required extends boolean> = {
type?: Type;
required?: Required;
values?: readonly Value[];
validator?: ((val: any) => val is Validator) | ((val: any) => boolean);
default?: EpPropInputDefault<Required, Default>;
};
/**
* output prop `buildProp` or `buildProps`.
*
* prop 输出参数。
*
* @example
* EpProp<'a', 'b', true>
* ⬇️
* {
readonly type: PropType<"a">;
readonly required: true;
readonly validator: ((val: unknown) => boolean) | undefined;
readonly default: "b";
__epPropKey: true;
}
*/
type EpProp<Type, Default, Required> = {
readonly type: PropType<Type>;
readonly required: [Required] extends [true] ? true : false;
readonly validator: ((val: unknown) => boolean) | undefined;
[epPropKey]: true;
} & IfNever<Default, unknown, {
readonly default: Default;
}>;
/**
* Determine if it is `EpProp`
*/
type IfEpProp<T, Y, N> = T extends {
[epPropKey]: true;
} ? Y : N;
/**
* Converting input to output.
*
* 将输入转换为输出
*/
type EpPropConvert<Input> = Input extends EpPropInput<infer Type, infer Value, infer Validator, any, infer Required> ? EpPropFinalized<Type, Value, Validator, Input['default'], Required> : never;
/**
* Finalized conversion output
*
* 最终转换 EpProp
*/
type EpPropFinalized<Type, Value, Validator, Default, Required> = EpProp<EpPropMergeType<Type, Value, Validator>, UnknownToNever<Default>, Required>;
//#endregion
export { EpProp, EpPropConvert, EpPropFinalized, EpPropInput, EpPropInputDefault, EpPropMergeType, ExtractPropType, IfEpProp, IfNativePropType, NativePropType, ResolvePropType };
View File
+8
View File
@@ -0,0 +1,8 @@
//#region ../../packages/utils/vue/props/util.d.ts
type Writable<T> = { -readonly [P in keyof T]: T[P] };
type WritableArray<T> = T extends readonly any[] ? Writable<T> : T;
type IfNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
type IfUnknown<T, Y, N> = [unknown] extends [T] ? Y : N;
type UnknownToNever<T> = IfUnknown<T, never, T>;
//#endregion
export { IfNever, IfUnknown, UnknownToNever, Writable, WritableArray };
View File
+6
View File
@@ -0,0 +1,6 @@
import { ComponentPublicInstance, Ref } from "vue";
//#region ../../packages/utils/vue/refs.d.ts
declare const composeRefs: (...refs: Ref<HTMLElement | undefined>[]) => (el: Element | ComponentPublicInstance | null) => void;
//#endregion
export { composeRefs };
+12
View File
@@ -0,0 +1,12 @@
//#region ../../packages/utils/vue/refs.ts
const composeRefs = (...refs) => {
return (el) => {
refs.forEach((ref) => {
ref.value = el;
});
};
};
//#endregion
export { composeRefs };
//# sourceMappingURL=refs.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"refs.mjs","names":[],"sources":["../../../../../packages/utils/vue/refs.ts"],"sourcesContent":["import type { ComponentPublicInstance, Ref } from 'vue'\n\nexport const composeRefs = (...refs: Ref<HTMLElement | undefined>[]) => {\n return (el: Element | ComponentPublicInstance | null) => {\n refs.forEach((ref) => {\n ref.value = el as HTMLElement | undefined\n })\n }\n}\n"],"mappings":";AAEA,MAAa,eAAe,GAAG,SAAyC;AACtE,SAAQ,OAAiD;AACvD,OAAK,SAAS,QAAQ;AACpB,OAAI,QAAQ;IACZ"}
+6
View File
@@ -0,0 +1,6 @@
import { ComponentSize } from "../../constants/size.js";
//#region ../../packages/utils/vue/size.d.ts
declare const getComponentSize: (size?: ComponentSize) => 40 | 24 | 32;
//#endregion
export { getComponentSize };
+10
View File
@@ -0,0 +1,10 @@
import { componentSizeMap } from "../../constants/size.mjs";
//#region ../../packages/utils/vue/size.ts
const getComponentSize = (size) => {
return componentSizeMap[size || "default"];
};
//#endregion
export { getComponentSize };
//# sourceMappingURL=size.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"size.mjs","names":[],"sources":["../../../../../packages/utils/vue/size.ts"],"sourcesContent":["import { componentSizeMap } from '@element-plus/constants'\n\nimport type { ComponentSize } from '@element-plus/constants'\n\nexport const getComponentSize = (size?: ComponentSize) => {\n return componentSizeMap[size || 'default']\n}\n"],"mappings":";;;AAIA,MAAa,oBAAoB,SAAyB;AACxD,QAAO,iBAAiB,QAAQ"}
+14
View File
@@ -0,0 +1,14 @@
import { AllowedComponentProps, AppContext, ComponentOptionsBase, EmitsOptions, ObjectPlugin, SetupContext, VNodeProps } from "vue";
//#region ../../packages/utils/vue/typescript.d.ts
type ExtractEventNames<T> = T extends (new (...args: any[]) => any) ? T extends ComponentOptionsBase<any, any, any, any, any, any, any, any> ? T['emits'] extends (string[] & ThisType<void>) | (infer Emits & ThisType<any>) | undefined ? keyof Emits extends string ? `on${Capitalize<keyof Emits>}` : Emits extends readonly string[] ? `on${Capitalize<Emits[number]>}` : never : never : never : never;
type SFCWithInstall<T> = T & ObjectPlugin & SFCWithPropsDefaultsSetter<T>;
type SFCInstallWithContext<T> = SFCWithInstall<T> & {
_context: AppContext | null;
};
type SFCWithPropsDefaultsSetter<T> = T extends (new (...args: any) => any) ? {
setPropsDefaults: (defaults: Partial<Omit<InstanceType<T>['$props'], ExtractEventNames<T> | keyof VNodeProps | keyof AllowedComponentProps>>) => void;
} : unknown;
type EmitFn<E extends EmitsOptions> = SetupContext<E>['emit'];
//#endregion
export { EmitFn, SFCInstallWithContext, SFCWithInstall, SFCWithPropsDefaultsSetter };
View File
+8
View File
@@ -0,0 +1,8 @@
import { DatePickType } from "../../constants/date.js";
import { ComponentSize } from "../../constants/size.js";
//#region ../../packages/utils/vue/validator.d.ts
declare const isValidComponentSize: (val: string) => val is ComponentSize | "";
declare const isValidDatePickType: (val: string) => val is DatePickType;
//#endregion
export { isValidComponentSize, isValidDatePickType };
+10
View File
@@ -0,0 +1,10 @@
import { datePickTypes } from "../../constants/date.mjs";
import { componentSizes } from "../../constants/size.mjs";
//#region ../../packages/utils/vue/validator.ts
const isValidComponentSize = (val) => ["", ...componentSizes].includes(val);
const isValidDatePickType = (val) => [...datePickTypes].includes(val);
//#endregion
export { isValidComponentSize, isValidDatePickType };
//# sourceMappingURL=validator.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"validator.mjs","names":[],"sources":["../../../../../packages/utils/vue/validator.ts"],"sourcesContent":["import { componentSizes, datePickTypes } from '@element-plus/constants'\n\nimport type { ComponentSize, DatePickType } from '@element-plus/constants'\n\nexport const isValidComponentSize = (val: string): val is ComponentSize | '' =>\n ['', ...componentSizes].includes(val)\n\nexport const isValidDatePickType = (val: string): val is DatePickType =>\n ([...datePickTypes] as string[]).includes(val)\n"],"mappings":";;;;AAIA,MAAa,wBAAwB,QACnC,CAAC,IAAI,GAAG,eAAe,CAAC,SAAS,IAAI;AAEvC,MAAa,uBAAuB,QACjC,CAAC,GAAG,cAAc,CAAc,SAAS,IAAI"}
+52
View File
@@ -0,0 +1,52 @@
import * as vue from "vue";
import { VNode, VNodeChild, VNodeNormalizedChildren, createBlock } from "vue";
//#region ../../packages/utils/vue/vnode.d.ts
declare enum PatchFlags {
TEXT = 1,
CLASS = 2,
STYLE = 4,
PROPS = 8,
FULL_PROPS = 16,
HYDRATE_EVENTS = 32,
STABLE_FRAGMENT = 64,
KEYED_FRAGMENT = 128,
UNKEYED_FRAGMENT = 256,
NEED_PATCH = 512,
DYNAMIC_SLOTS = 1024,
HOISTED = -1,
BAIL = -2
}
type VNodeChildAtom = Exclude<VNodeChild, Array<any>>;
type RawSlots = Exclude<VNodeNormalizedChildren, Array<any> | null | string>;
declare function isFragment(node: VNode): boolean;
declare function isFragment(node: unknown): node is VNode;
declare function isText(node: VNode): boolean;
declare function isText(node: unknown): node is VNode;
declare function isComment(node: VNode): boolean;
declare function isComment(node: unknown): node is VNode;
declare function isTemplate(node: VNode): boolean;
declare function isTemplate(node: unknown): node is VNode;
/**
* determine if the element is a valid element type rather than fragments and comment e.g. <template> v-if
* @param node {VNode} node to be tested
*/
declare function isValidElementNode(node: VNode): boolean;
declare function isValidElementNode(node: unknown): node is VNode;
declare const getFirstValidNode: (nodes: VNodeNormalizedChildren, maxDepth?: number) => string | number | boolean | void | VNode<vue.RendererNode, vue.RendererElement, {
[key: string]: any;
}> | vue.VNodeArrayChildren | {
[name: string]: unknown;
$stable?: boolean;
} | null | undefined;
declare function renderIf(condition: boolean, ...args: Parameters<typeof createBlock>): VNode<vue.RendererNode, vue.RendererElement, {
[key: string]: any;
}>;
declare function renderBlock(...args: Parameters<typeof createBlock>): VNode<vue.RendererNode, vue.RendererElement, {
[key: string]: any;
}>;
declare const getNormalizedProps: (node: VNode) => Record<string, any>;
type FlattenVNodes = Array<VNodeChildAtom | RawSlots>;
declare const flattedChildren: (children: FlattenVNodes | VNode | VNodeNormalizedChildren) => FlattenVNodes;
//#endregion
export { FlattenVNodes, PatchFlags, RawSlots, VNodeChildAtom, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf };
+92
View File
@@ -0,0 +1,92 @@
import { isArray } from "../types.mjs";
import { camelize } from "../strings.mjs";
import { hasOwn } from "../objects.mjs";
import { debugWarn } from "../error.mjs";
import { Comment, Fragment, Text, createBlock, createCommentVNode, isVNode, openBlock } from "vue";
//#region ../../packages/utils/vue/vnode.ts
const SCOPE = "utils/vue/vnode";
let PatchFlags = /* @__PURE__ */ function(PatchFlags) {
PatchFlags[PatchFlags["TEXT"] = 1] = "TEXT";
PatchFlags[PatchFlags["CLASS"] = 2] = "CLASS";
PatchFlags[PatchFlags["STYLE"] = 4] = "STYLE";
PatchFlags[PatchFlags["PROPS"] = 8] = "PROPS";
PatchFlags[PatchFlags["FULL_PROPS"] = 16] = "FULL_PROPS";
PatchFlags[PatchFlags["HYDRATE_EVENTS"] = 32] = "HYDRATE_EVENTS";
PatchFlags[PatchFlags["STABLE_FRAGMENT"] = 64] = "STABLE_FRAGMENT";
PatchFlags[PatchFlags["KEYED_FRAGMENT"] = 128] = "KEYED_FRAGMENT";
PatchFlags[PatchFlags["UNKEYED_FRAGMENT"] = 256] = "UNKEYED_FRAGMENT";
PatchFlags[PatchFlags["NEED_PATCH"] = 512] = "NEED_PATCH";
PatchFlags[PatchFlags["DYNAMIC_SLOTS"] = 1024] = "DYNAMIC_SLOTS";
PatchFlags[PatchFlags["HOISTED"] = -1] = "HOISTED";
PatchFlags[PatchFlags["BAIL"] = -2] = "BAIL";
return PatchFlags;
}({});
function isFragment(node) {
return isVNode(node) && node.type === Fragment;
}
function isText(node) {
return isVNode(node) && node.type === Text;
}
function isComment(node) {
return isVNode(node) && node.type === Comment;
}
const TEMPLATE = "template";
function isTemplate(node) {
return isVNode(node) && node.type === TEMPLATE;
}
function isValidElementNode(node) {
return isVNode(node) && !isFragment(node) && !isComment(node);
}
/**
* get a valid child node (not fragment nor comment)
* @param node {VNode} node to be searched
* @param depth {number} depth to be searched
*/
function getChildren(node, depth) {
if (isComment(node)) return;
if (isFragment(node) || isTemplate(node)) return depth > 0 ? getFirstValidNode(node.children, depth - 1) : void 0;
return node;
}
const getFirstValidNode = (nodes, maxDepth = 3) => {
if (isArray(nodes)) return getChildren(nodes[0], maxDepth);
else return getChildren(nodes, maxDepth);
};
function renderIf(condition, ...args) {
return condition ? renderBlock(...args) : createCommentVNode("v-if", true);
}
function renderBlock(...args) {
return openBlock(), createBlock(...args);
}
const getNormalizedProps = (node) => {
if (!isVNode(node)) {
debugWarn(SCOPE, "[getNormalizedProps] must be a VNode");
return {};
}
const raw = node.props || {};
const type = (isVNode(node.type) ? node.type.props : void 0) || {};
const props = {};
Object.keys(type).forEach((key) => {
if (hasOwn(type[key], "default")) props[key] = type[key].default;
});
Object.keys(raw).forEach((key) => {
props[camelize(key)] = raw[key];
});
return props;
};
const flattedChildren = (children) => {
const vNodes = isArray(children) ? children : [children];
const result = [];
vNodes.forEach((child) => {
if (isArray(child)) result.push(...flattedChildren(child));
else if (isVNode(child) && child.component?.subTree) result.push(child, ...flattedChildren(child.component.subTree));
else if (isVNode(child) && isArray(child.children)) result.push(...flattedChildren(child.children));
else if (isVNode(child) && child.shapeFlag === 2) result.push(...flattedChildren(child.type()));
else result.push(child);
});
return result;
};
//#endregion
export { PatchFlags, flattedChildren, getFirstValidNode, getNormalizedProps, isComment, isFragment, isTemplate, isText, isValidElementNode, renderBlock, renderIf };
//# sourceMappingURL=vnode.mjs.map
File diff suppressed because one or more lines are too long