@v-c/util 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/props-util/index.cjs +1 -1
  2. package/dist/props-util/index.d.ts +2 -3
  3. package/dist/props-util/index.js +18 -20
  4. package/package.json +5 -1
  5. package/dist/props-util/initDefaultProps.cjs +0 -1
  6. package/dist/props-util/initDefaultProps.d.ts +0 -8
  7. package/dist/props-util/initDefaultProps.js +0 -13
  8. package/src/Children/isFragment.ts +0 -6
  9. package/src/Children/tests/isFragment.test.tsx +0 -15
  10. package/src/Children/tests/toArray.test.tsx +0 -101
  11. package/src/Children/toArray.ts +0 -27
  12. package/src/Dom/addEventListener.ts +0 -20
  13. package/src/Dom/canUseDom.ts +0 -7
  14. package/src/Dom/class.ts +0 -29
  15. package/src/Dom/contains.ts +0 -19
  16. package/src/Dom/css.ts +0 -113
  17. package/src/Dom/dynamicCSS.ts +0 -173
  18. package/src/Dom/findDOMNode.ts +0 -23
  19. package/src/Dom/focus.ts +0 -96
  20. package/src/Dom/isVisible.ts +0 -23
  21. package/src/Dom/scrollLocker.ts +0 -144
  22. package/src/Dom/shadow.ts +0 -17
  23. package/src/Dom/styleChecker.ts +0 -31
  24. package/src/Dom/support.ts +0 -27
  25. package/src/EventInterface.ts +0 -19
  26. package/src/KeyCode.ts +0 -517
  27. package/src/Portal.tsx +0 -50
  28. package/src/PortalWrapper.tsx +0 -217
  29. package/src/composeProps.ts +0 -23
  30. package/src/createRef.ts +0 -32
  31. package/src/debug/diff.ts +0 -66
  32. package/src/deprecated.ts +0 -8
  33. package/src/getScrollBarSize.tsx +0 -57
  34. package/src/guid.ts +0 -4
  35. package/src/hooks/useEvent.ts +0 -3
  36. package/src/hooks/useId.ts +0 -20
  37. package/src/hooks/useLayoutEffect.ts +0 -61
  38. package/src/hooks/useMemo.ts +0 -21
  39. package/src/hooks/useMergedState.ts +0 -44
  40. package/src/hooks/useMobile.ts +0 -16
  41. package/src/hooks/useState.ts +0 -17
  42. package/src/index.ts +0 -3
  43. package/src/isEqual.ts +0 -50
  44. package/src/isMobile.ts +0 -15
  45. package/src/isValid.ts +0 -4
  46. package/src/omit.ts +0 -14
  47. package/src/pickAttrs.ts +0 -79
  48. package/src/props-util/index.ts +0 -57
  49. package/src/props-util/initDefaultProps.ts +0 -34
  50. package/src/raf.ts +0 -55
  51. package/src/setStyle.ts +0 -38
  52. package/src/switchScrollingEffect.ts +0 -48
  53. package/src/test/domHook.ts +0 -66
  54. package/src/type.ts +0 -94
  55. package/src/utils/checkSlotProp.ts +0 -10
  56. package/src/utils/get.ts +0 -15
  57. package/src/utils/omit.ts +0 -9
  58. package/src/utils/set.ts +0 -110
  59. package/src/utils/transition.ts +0 -128
  60. package/src/vnode.ts +0 -86
  61. package/src/vueuse/unref-element.ts +0 -13
  62. package/src/warning.ts +0 -79
  63. package/tests/Portal.spec.tsx +0 -199
  64. package/tsconfig.json +0 -8
  65. package/vite.config.ts +0 -18
  66. package/vitest.config.ts +0 -11
package/src/Dom/focus.ts DELETED
@@ -1,96 +0,0 @@
1
- import isVisible from './isVisible'
2
-
3
- type DisabledElement =
4
- | HTMLLinkElement
5
- | HTMLInputElement
6
- | HTMLFieldSetElement
7
- | HTMLButtonElement
8
- | HTMLOptGroupElement
9
- | HTMLOptionElement
10
- | HTMLSelectElement
11
- | HTMLTextAreaElement
12
-
13
- function focusable(node: HTMLElement, includePositive = false): boolean {
14
- if (isVisible(node)) {
15
- const nodeName = node.nodeName.toLowerCase()
16
- const isFocusableElement
17
- // Focusable element
18
- = ['input', 'select', 'textarea', 'button'].includes(nodeName)
19
- // Editable element
20
- || node.isContentEditable
21
- // Anchor with href element
22
- || (nodeName === 'a' && !!node.getAttribute('href'))
23
-
24
- // Get tabIndex
25
- const tabIndexAttr = node.getAttribute('tabindex')
26
- const tabIndexNum = Number(tabIndexAttr)
27
-
28
- // Parse as number if validate
29
- let tabIndex: number | null = null
30
- if (tabIndexAttr && !Number.isNaN(tabIndexNum))
31
- tabIndex = tabIndexNum
32
- else if (isFocusableElement && tabIndex === null)
33
- tabIndex = 0
34
-
35
- // Block focusable if disabled
36
- if (isFocusableElement && (node as DisabledElement).disabled)
37
- tabIndex = null
38
-
39
- return (
40
- tabIndex !== null && (tabIndex >= 0 || (includePositive && tabIndex < 0))
41
- )
42
- }
43
-
44
- return false
45
- }
46
-
47
- export function getFocusNodeList(node: HTMLElement, includePositive = false) {
48
- const res = [...node.querySelectorAll<HTMLElement>('*')].filter((child) => {
49
- return focusable(child, includePositive)
50
- })
51
- if (focusable(node, includePositive))
52
- res.unshift(node)
53
-
54
- return res
55
- }
56
-
57
- let lastFocusElement: any = null
58
-
59
- /** @deprecated Do not use since this may failed when used in async */
60
- export function saveLastFocusNode() {
61
- lastFocusElement = document.activeElement
62
- }
63
-
64
- /** @deprecated Do not use since this may failed when used in async */
65
- export function clearLastFocusNode() {
66
- lastFocusElement = null
67
- }
68
-
69
- /** @deprecated Do not use since this may failed when used in async */
70
- export function backLastFocusNode() {
71
- if (lastFocusElement) {
72
- try {
73
- // 元素可能已经被移动了
74
- lastFocusElement.focus()
75
- }
76
-
77
- catch (_e: any) {
78
- // empty
79
- }
80
- }
81
- }
82
-
83
- export function limitTabRange(node: HTMLElement, e: KeyboardEvent) {
84
- if (e.keyCode === 9) {
85
- const tabNodeList = getFocusNodeList(node)
86
- const lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1]
87
- const leavingTab
88
- = lastTabNode === document.activeElement || node === document.activeElement
89
-
90
- if (leavingTab) {
91
- const target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0]
92
- target.focus()
93
- e.preventDefault()
94
- }
95
- }
96
- }
@@ -1,23 +0,0 @@
1
- export default (element: Element): boolean => {
2
- if (!element)
3
- return false
4
-
5
- if (element instanceof Element) {
6
- if ((element as HTMLElement).offsetParent)
7
- return true
8
-
9
- if ((element as SVGGraphicsElement).getBBox) {
10
- const { width, height } = (element as SVGGraphicsElement).getBBox()
11
- if (width || height)
12
- return true
13
- }
14
-
15
- if (element.getBoundingClientRect) {
16
- const { width, height } = element.getBoundingClientRect()
17
- if (width || height)
18
- return true
19
- }
20
- }
21
-
22
- return false
23
- }
@@ -1,144 +0,0 @@
1
- import type { CSSProperties } from 'vue'
2
- import getScrollBarSize from '../getScrollBarSize'
3
- import setStyle from '../setStyle'
4
-
5
- export interface scrollLockOptions {
6
- container: HTMLElement
7
- }
8
-
9
- let uuid = 0
10
-
11
- interface Ilocks {
12
- target: typeof uuid
13
- options: scrollLockOptions
14
- }
15
-
16
- let locks: Ilocks[] = []
17
- const scrollingEffectClassName = 'ant-scrolling-effect'
18
- const scrollingEffectClassNameReg = new RegExp(
19
- `${scrollingEffectClassName}`,
20
- 'g',
21
- )
22
-
23
- // https://github.com/ant-design/ant-design/issues/19340
24
- // https://github.com/ant-design/ant-design/issues/19332
25
- const cacheStyle = new Map<Element, CSSProperties>()
26
-
27
- export default class ScrollLocker {
28
- private readonly lockTarget: typeof uuid
29
-
30
- private options: scrollLockOptions | undefined
31
-
32
- constructor(options?: scrollLockOptions) {
33
- this.lockTarget = uuid++
34
- this.options = options
35
- }
36
-
37
- getContainer = (): HTMLElement | undefined => {
38
- return this.options?.container
39
- }
40
-
41
- // if options change...
42
- reLock = (options?: scrollLockOptions) => {
43
- const findLock = locks.find(({ target }) => target === this.lockTarget)
44
-
45
- if (findLock)
46
- this.unLock()
47
-
48
- this.options = options
49
-
50
- if (findLock) {
51
- findLock.options = options!
52
-
53
- this.lock()
54
- }
55
- }
56
-
57
- lock = () => {
58
- // If lockTarget exist return
59
- if (locks.some(({ target }) => target === this.lockTarget))
60
- return
61
-
62
- // If same container effect, return
63
- if (
64
- locks.some(
65
- ({ options }) => options?.container === this.options?.container,
66
- )
67
- ) {
68
- locks = [...locks!, { target: this.lockTarget, options: this.options! }]
69
- return
70
- }
71
-
72
- let scrollBarSize = 0
73
- const container = this.options?.container || document.body
74
-
75
- if (
76
- (container === document.body
77
- && window.innerWidth - document.documentElement.clientWidth > 0)
78
- || container.scrollHeight > container.clientHeight
79
- ) {
80
- if (getComputedStyle(container).overflow !== 'hidden')
81
- scrollBarSize = getScrollBarSize()
82
- }
83
-
84
- const containerClassName = container.className
85
-
86
- if (
87
- locks.filter(
88
- ({ options }) => options?.container === this.options?.container,
89
- ).length === 0
90
- ) {
91
- cacheStyle.set(
92
- container,
93
- setStyle(
94
- {
95
- width:
96
- scrollBarSize !== 0
97
- ? `calc(100% - ${scrollBarSize}px)`
98
- : undefined,
99
- overflow: 'hidden',
100
- overflowX: 'hidden',
101
- overflowY: 'hidden',
102
- },
103
- { element: container },
104
- ),
105
- )
106
- }
107
-
108
- // https://github.com/ant-design/ant-design/issues/19729
109
- if (!scrollingEffectClassNameReg.test(containerClassName)) {
110
- const addClassName = `${containerClassName} ${scrollingEffectClassName}`
111
- container.className = addClassName.trim()
112
- }
113
-
114
- locks = [...locks!, { target: this.lockTarget, options: this.options! }]
115
- }
116
-
117
- unLock = () => {
118
- const findLock = locks.find(({ target }) => target === this.lockTarget)
119
-
120
- locks = locks.filter(({ target }) => target !== this.lockTarget)
121
-
122
- if (
123
- !findLock
124
- || locks.some(
125
- ({ options }) => options?.container === findLock.options?.container,
126
- )
127
- ) {
128
- return
129
- }
130
-
131
- // Remove Effect
132
- const container = this.options?.container || document.body
133
- const containerClassName = container.className
134
-
135
- if (!scrollingEffectClassNameReg.test(containerClassName))
136
- return
137
-
138
- setStyle(cacheStyle.get(container)!, { element: container })
139
- cacheStyle.delete(container)
140
- container.className = container.className
141
- .replace(scrollingEffectClassNameReg, '')
142
- .trim()
143
- }
144
- }
package/src/Dom/shadow.ts DELETED
@@ -1,17 +0,0 @@
1
- function getRoot(ele: Node) {
2
- return ele?.getRootNode?.()
3
- }
4
-
5
- /**
6
- * Check if is in shadowRoot
7
- */
8
- export function inShadow(ele: Node) {
9
- return getRoot(ele) instanceof ShadowRoot
10
- }
11
-
12
- /**
13
- * Return shadowRoot if possible
14
- */
15
- export function getShadowRoot(ele: Node): ShadowRoot | null {
16
- return inShadow(ele) ? (getRoot(ele) as ShadowRoot) : null
17
- }
@@ -1,31 +0,0 @@
1
- import canUseDom from './canUseDom'
2
-
3
- function isStyleNameSupport(styleName: string | string[]): boolean {
4
- if (canUseDom() && window.document.documentElement) {
5
- const styleNameList = Array.isArray(styleName) ? styleName : [styleName]
6
- const { documentElement } = window.document
7
-
8
- return styleNameList.some(name => name in documentElement.style)
9
- }
10
- return false
11
- }
12
-
13
- function isStyleValueSupport(styleName: string, value: any) {
14
- if (!isStyleNameSupport(styleName))
15
- return false
16
-
17
- const ele: any = document.createElement('div')
18
- const origin = ele.style[styleName]
19
- ele.style[styleName] = value
20
- return ele.style[styleName] !== origin
21
- }
22
-
23
- export function isStyleSupport(styleName: string | string[]): boolean
24
- export function isStyleSupport(styleName: string, styleValue: any): boolean
25
-
26
- export function isStyleSupport(styleName: string | string[], styleValue?: any) {
27
- if (!Array.isArray(styleName) && styleValue !== undefined)
28
- return isStyleValueSupport(styleName, styleValue)
29
-
30
- return isStyleNameSupport(styleName)
31
- }
@@ -1,27 +0,0 @@
1
- import canUseDOM from './canUseDom'
2
-
3
- const animationEndEventNames = {
4
- WebkitAnimation: 'webkitAnimationEnd',
5
- OAnimation: 'oAnimationEnd',
6
- animation: 'animationend',
7
- }
8
- const transitionEventNames = {
9
- WebkitTransition: 'webkitTransitionEnd',
10
- OTransition: 'oTransitionEnd',
11
- transition: 'transitionend',
12
- }
13
-
14
- function supportEnd(names: Record<string, any>) {
15
- const el: any = document.createElement('div')
16
- for (const name in names) {
17
- if (names.hasOwnProperty(name) && el.style[name] !== undefined) {
18
- return {
19
- end: names[name],
20
- }
21
- }
22
- }
23
- return false
24
- }
25
-
26
- export const animation = canUseDOM() && supportEnd(animationEndEventNames)
27
- export const transition = canUseDOM() && supportEnd(transitionEventNames)
@@ -1,19 +0,0 @@
1
- export type FocusEventHandler = (e: FocusEvent) => void
2
- export type MouseEventHandler = (e: MouseEvent) => void
3
- export type KeyboardEventHandler = (e: KeyboardEvent) => void
4
- export type CompositionEventHandler = (e: CompositionEvent) => void
5
- export type ClipboardEventHandler = (e: ClipboardEvent) => void
6
- export type ChangeEventHandler = (e: ChangeEvent) => void
7
- export type WheelEventHandler = (e: WheelEvent) => void
8
- export type ChangeEvent = Event & {
9
- target: {
10
- value?: string | undefined
11
- }
12
- }
13
- export type CheckboxChangeEvent = Event & {
14
- target: {
15
- checked?: boolean
16
- }
17
- }
18
-
19
- export type EventHandler = (...args: any[]) => void