@king-one/antdv 1.0.72 → 1.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @king-one/antdv
2
2
 
3
+ ## 1.0.73
4
+
5
+ ### Patch Changes
6
+
7
+ - fix:优化
8
+
3
9
  ## 1.0.72
4
10
 
5
11
  ### Patch Changes
@@ -61,7 +61,7 @@ function W(r, t, a, n, { containerRef: c, state: e, currentList: o, source: l },
61
61
  e.value = {
62
62
  start: p < 0 ? 0 : p,
63
63
  end: g > l.value.length ? l.value.length : g,
64
- current: f,
64
+ current: f - 1,
65
65
  scale: e.value.scale
66
66
  }, o.value = l.value.slice(e.value.start, e.value.end).map((h, v) => ({
67
67
  data: h,
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualList.mjs","sources":["../../../../../components/scale-virtual-list/hooks/useVirtualList.ts"],"sourcesContent":["import { type EventHookOn, type MaybeRef, createEventHook } from '@vueuse/shared'\nimport type { ComputedRef, Ref, ShallowRef, StyleValue } from 'vue'\nimport { computed, ref, shallowRef, watch } from 'vue'\nimport { useElementSize } from '@vueuse/core'\n\nexport interface UseVirtualListState { start: number, end: number, current: number, scale: number }\n\ntype RefState = Ref<UseVirtualListState>\ntype UseVirtualListItemSize = number | ((index: number) => number)\n\nexport interface UseHorizontalVirtualListOptions extends UseVirtualListOptionsBase {\n\n /**\n * item width, accept a pixel value or a function that returns the width\n *\n * @default 0\n */\n itemWidth: UseVirtualListItemSize\n\n}\n\nexport interface UseVerticalVirtualListOptions extends UseVirtualListOptionsBase {\n /**\n * item height, accept a pixel value or a function that returns the height\n *\n * @default 0\n */\n itemHeight: UseVirtualListItemSize\n}\n\nexport interface UseVirtualListOptionsBase {\n /**\n * the extra buffer items outside of the view area\n *\n * @default 5\n */\n overscan?: number\n}\n\nexport type UseVirtualListOptions = UseHorizontalVirtualListOptions | UseVerticalVirtualListOptions\n\nexport interface UseVirtualListItem<T> {\n data: T\n index: number\n}\n\nexport interface UseVirtualListReturn<T> {\n onUpdate: EventHookOn<UseVirtualListState | null>\n state: RefState\n list: Ref<UseVirtualListItem<T>[]>\n scrollTo: (index: number) => void\n scaleTo: (s: number) => void\n containerProps: {\n ref: Ref<HTMLElement | null>\n onScroll: () => void\n style: StyleValue\n }\n wrapperProps: ComputedRef<{\n style: {\n height: string\n marginTop: string\n transform: string\n transformOrigin: string\n } | {\n width: string\n height: string\n marginLeft: string\n display: string\n transform: string\n transformOrigin: string\n }\n }>\n}\n\n/**\n * Please consider using [`vue-virtual-scroller`](https://github.com/Akryum/vue-virtual-scroller) if you are looking for more features.\n */\nexport function useVirtualList<T = any>(list: MaybeRef<T[]>, options: UseVirtualListOptions): UseVirtualListReturn<T> {\n const { containerStyle, wrapperProps, scrollTo, calculateRange, currentList, containerRef, scaleTo, state, onUpdate } = 'itemHeight' in options\n ? useVerticalVirtualList(options, list)\n : useHorizontalVirtualList(options, list)\n\n return {\n onUpdate,\n state,\n scaleTo,\n list: currentList,\n scrollTo,\n containerProps: {\n ref: containerRef,\n onScroll: () => {\n calculateRange()\n },\n style: containerStyle\n },\n wrapperProps\n }\n}\n\ntype UseVirtualListContainerRef = Ref<HTMLElement | null>\n\ninterface UseVirtualElementSizes {\n width: Ref<number>\n height: Ref<number>\n}\n\ntype UseVirtualListArray<T> = UseVirtualListItem<T>[]\ntype UseVirtualListRefArray<T> = Ref<UseVirtualListArray<T>>\n\ntype UseVirtualListSource<T> = Ref<T[]> | ShallowRef<T[]>\n\ninterface UseVirtualListResources<T> {\n state: RefState\n source: UseVirtualListSource<T>\n currentList: UseVirtualListRefArray<T>\n size: UseVirtualElementSizes\n containerRef: UseVirtualListContainerRef\n}\n\nfunction useVirtualListResources<T>(list: MaybeRef<T[]>): UseVirtualListResources<T> {\n const containerRef = ref<HTMLElement | null>(null)\n const size = useElementSize(containerRef)\n\n const currentList: Ref<UseVirtualListItem<T>[]> = ref([])\n const source = shallowRef(list)\n\n const state: Ref<UseVirtualListState> = ref({ start: 0, end: 10, current: 0, scale: 1 })\n\n return { state, source, currentList, size, containerRef }\n}\n\nfunction createGetViewCapacity<T>(state: UseVirtualListResources<T>['state'], source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize) {\n return (containerSize: number) => {\n const { start = 0, scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.ceil(containerSize / (itemSize * scale))\n\n let sum = 0\n let capacity = 0\n for (let i = start; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n capacity = i\n if (sum > containerSize)\n break\n }\n return capacity - start\n }\n}\n// 根据滚动条获取索引\nfunction createGetOffset<T>(source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize, state: UseVirtualListResources<T>['state']) {\n return (scrollDirection: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.floor(scrollDirection / (itemSize * scale)) + 1\n\n let sum = 0\n let offset = 0\n\n for (let i = 0; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n if (sum >= scrollDirection) {\n offset = i\n break\n }\n }\n return offset + 1\n }\n}\n\nfunction createCalculateRange<T>(type: 'horizontal' | 'vertical', overscan: number, getOffset: ReturnType<typeof createGetOffset>, getViewCapacity: ReturnType<typeof createGetViewCapacity>, { containerRef, state, currentList, source }: UseVirtualListResources<T>, updateTrigger) {\n return () => {\n const element = containerRef.value\n if (element) {\n const offset = getOffset(type === 'vertical' ? element.scrollTop : element.scrollLeft)\n const viewCapacity = getViewCapacity(type === 'vertical' ? element.clientHeight : element.clientWidth)\n\n const from = offset - overscan\n const to = offset + viewCapacity + overscan\n\n state.value = {\n start: from < 0 ? 0 : from,\n end: to > source.value.length\n ? source.value.length\n : to,\n current: offset,\n scale: state.value.scale\n }\n currentList.value = source.value\n .slice(state.value.start, state.value.end)\n .map((ele, index) => ({\n data: ele,\n index: index + state.value.start\n }))\n updateTrigger(state.value)\n }\n }\n}\n// 获取距离\nfunction createGetDistance<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return (index: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number') {\n const size = index * (itemSize * scale)\n return Math.ceil(size)\n }\n\n const size = source.value\n .slice(0, index)\n .reduce((sum, _, i) => sum + itemSize(i) * scale, 0)\n\n return Math.ceil(size)\n }\n}\n\nfunction useWatchForSizes<T>(size: UseVirtualElementSizes, list: MaybeRef<T[]>, containerRef: Ref<HTMLElement | null>, calculateRange: () => void) {\n watch([size.width, size.height, list, containerRef], () => {\n calculateRange()\n })\n}\n// 获取总高度\nfunction createComputedTotalSize<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return computed(() => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return source.value.length * itemSize * scale\n\n return source.value.reduce((sum, _, index) => sum + itemSize(index) * scale, 0)\n })\n}\n\nconst scrollToDictionaryForElementScrollKey = {\n horizontal: 'scrollLeft',\n vertical: 'scrollTop'\n} as const\n\nfunction createScrollTo<T>(type: 'horizontal' | 'vertical', calculateRange: () => void, getDistance: ReturnType<typeof createGetDistance>, containerRef: UseVirtualListResources<T>['containerRef']) {\n return (index: number) => {\n if (containerRef.value) {\n containerRef.value[scrollToDictionaryForElementScrollKey[type]] = getDistance(index)\n calculateRange()\n }\n }\n}\n\nfunction useHorizontalVirtualList<T>(options: UseHorizontalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n const { state, source, currentList, size, containerRef } = resources\n const containerStyle: StyleValue = { overflowX: 'auto' }\n\n const { itemWidth, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemWidth)\n\n const getOffset = createGetOffset(source, itemWidth, state)\n\n const calculateRange = createCalculateRange('horizontal', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceLeft = createGetDistance(itemWidth, source, state)\n\n const offsetLeft = computed(() => getDistanceLeft(state.value.start))\n\n const totalWidth = createComputedTotalSize(itemWidth, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('horizontal', calculateRange, getDistanceLeft, containerRef)\n const scaleTo = (s: number) => {\n state.value.scale = s\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: '100%',\n width: `${totalWidth.value - offsetLeft.value}px`,\n marginLeft: `${offsetLeft.value}px`,\n display: 'flex',\n transform: `scale(${state.value.scale})`,\n transformOrigin: '0% 0%'\n // position: 'absolute',\n // left: '50%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n scrollTo,\n calculateRange,\n wrapperProps,\n containerStyle,\n currentList,\n containerRef\n }\n}\n\nfunction useVerticalVirtualList<T>(options: UseVerticalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n\n const { state, source, currentList, size, containerRef } = resources\n\n const containerStyle: StyleValue = { overflowY: 'auto' }\n\n const { itemHeight, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemHeight)\n\n const getOffset = createGetOffset(source, itemHeight, state)\n\n const calculateRange = createCalculateRange('vertical', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceTop = createGetDistance(itemHeight, source, state)\n\n const offsetTop = computed(() => getDistanceTop(state.value.start))\n\n const totalHeight = createComputedTotalSize(itemHeight, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('vertical', calculateRange, getDistanceTop, containerRef)\n const scaleTo = (s: number) => {\n // state.value.scale = s\n const element = containerRef.value\n if (element) {\n const { current } = state.value\n let offsetScroll = 0\n if (typeof itemHeight === 'number') {\n offsetScroll = current * (s * itemHeight - state.value.scale * itemHeight)\n }\n else {\n offsetScroll = source.value.slice(0, current).reduce((sum, _, i) => sum + s * itemHeight(i) - state.value.scale * itemHeight(i), 0)\n }\n element.scrollTop = element.scrollTop + offsetScroll >= 0 ? element.scrollTop + offsetScroll : 0\n state.value.scale = s\n }\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: `${totalHeight.value - offsetTop.value}px`,\n marginTop: `${offsetTop.value}px`,\n transform: `translateX(-50%) scale(${state.value.scale})`,\n transformOrigin: '50% 0%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n calculateRange,\n scrollTo,\n containerStyle,\n wrapperProps,\n currentList,\n containerRef\n }\n}\n"],"names":["useVirtualList","list","options","containerStyle","wrapperProps","scrollTo","calculateRange","currentList","containerRef","scaleTo","state","onUpdate","useVerticalVirtualList","useHorizontalVirtualList","useVirtualListResources","ref","size","useElementSize","source","shallowRef","createGetViewCapacity","itemSize","containerSize","start","scale","sum","capacity","i","createGetOffset","scrollDirection","offset","createCalculateRange","type","overscan","getOffset","getViewCapacity","updateTrigger","element","viewCapacity","from","to","ele","index","createGetDistance","_","useWatchForSizes","watch","createComputedTotalSize","computed","scrollToDictionaryForElementScrollKey","createScrollTo","getDistance","createEventHook","resources","itemWidth","getDistanceLeft","offsetLeft","totalWidth","s","itemHeight","getDistanceTop","offsetTop","totalHeight","current","offsetScroll"],"mappings":";;;AA6EgB,SAAAA,EAAwBC,GAAqBC,GAAyD;AACpH,QAAM,EAAE,gBAAAC,GAAgB,cAAAC,GAAc,UAAAC,GAAU,gBAAAC,GAAgB,aAAAC,GAAa,cAAAC,GAAc,SAAAC,GAAS,OAAAC,GAAO,UAAAC,EAAa,IAAA,gBAAgBT,IACpIU,EAAuBV,GAASD,CAAI,IACpCY,EAAyBX,GAASD,CAAI;AAEnC,SAAA;AAAA,IACL,UAAAU;AAAA,IACA,OAAAD;AAAA,IACA,SAAAD;AAAA,IACA,MAAMF;AAAA,IACN,UAAAF;AAAA,IACA,gBAAgB;AAAA,MACd,KAAKG;AAAA,MACL,UAAU,MAAM;AACC,QAAAF;MACjB;AA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BAAAF;AAAA,IACA,cAAAC;AAAA,IACA,aAAAG;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useVirtualList.mjs","sources":["../../../../../components/scale-virtual-list/hooks/useVirtualList.ts"],"sourcesContent":["import { type EventHookOn, type MaybeRef, createEventHook } from '@vueuse/shared'\nimport type { ComputedRef, Ref, ShallowRef, StyleValue } from 'vue'\nimport { computed, ref, shallowRef, watch } from 'vue'\nimport { useElementSize } from '@vueuse/core'\n\nexport interface UseVirtualListState { start: number, end: number, current: number, scale: number }\n\ntype RefState = Ref<UseVirtualListState>\ntype UseVirtualListItemSize = number | ((index: number) => number)\n\nexport interface UseHorizontalVirtualListOptions extends UseVirtualListOptionsBase {\n\n /**\n * item width, accept a pixel value or a function that returns the width\n *\n * @default 0\n */\n itemWidth: UseVirtualListItemSize\n\n}\n\nexport interface UseVerticalVirtualListOptions extends UseVirtualListOptionsBase {\n /**\n * item height, accept a pixel value or a function that returns the height\n *\n * @default 0\n */\n itemHeight: UseVirtualListItemSize\n}\n\nexport interface UseVirtualListOptionsBase {\n /**\n * the extra buffer items outside of the view area\n *\n * @default 5\n */\n overscan?: number\n}\n\nexport type UseVirtualListOptions = UseHorizontalVirtualListOptions | UseVerticalVirtualListOptions\n\nexport interface UseVirtualListItem<T> {\n data: T\n index: number\n}\n\nexport interface UseVirtualListReturn<T> {\n onUpdate: EventHookOn<UseVirtualListState | null>\n state: RefState\n list: Ref<UseVirtualListItem<T>[]>\n scrollTo: (index: number) => void\n scaleTo: (s: number) => void\n containerProps: {\n ref: Ref<HTMLElement | null>\n onScroll: () => void\n style: StyleValue\n }\n wrapperProps: ComputedRef<{\n style: {\n height: string\n marginTop: string\n transform: string\n transformOrigin: string\n } | {\n width: string\n height: string\n marginLeft: string\n display: string\n transform: string\n transformOrigin: string\n }\n }>\n}\n\n/**\n * Please consider using [`vue-virtual-scroller`](https://github.com/Akryum/vue-virtual-scroller) if you are looking for more features.\n */\nexport function useVirtualList<T = any>(list: MaybeRef<T[]>, options: UseVirtualListOptions): UseVirtualListReturn<T> {\n const { containerStyle, wrapperProps, scrollTo, calculateRange, currentList, containerRef, scaleTo, state, onUpdate } = 'itemHeight' in options\n ? useVerticalVirtualList(options, list)\n : useHorizontalVirtualList(options, list)\n\n return {\n onUpdate,\n state,\n scaleTo,\n list: currentList,\n scrollTo,\n containerProps: {\n ref: containerRef,\n onScroll: () => {\n calculateRange()\n },\n style: containerStyle\n },\n wrapperProps\n }\n}\n\ntype UseVirtualListContainerRef = Ref<HTMLElement | null>\n\ninterface UseVirtualElementSizes {\n width: Ref<number>\n height: Ref<number>\n}\n\ntype UseVirtualListArray<T> = UseVirtualListItem<T>[]\ntype UseVirtualListRefArray<T> = Ref<UseVirtualListArray<T>>\n\ntype UseVirtualListSource<T> = Ref<T[]> | ShallowRef<T[]>\n\ninterface UseVirtualListResources<T> {\n state: RefState\n source: UseVirtualListSource<T>\n currentList: UseVirtualListRefArray<T>\n size: UseVirtualElementSizes\n containerRef: UseVirtualListContainerRef\n}\n\nfunction useVirtualListResources<T>(list: MaybeRef<T[]>): UseVirtualListResources<T> {\n const containerRef = ref<HTMLElement | null>(null)\n const size = useElementSize(containerRef)\n\n const currentList: Ref<UseVirtualListItem<T>[]> = ref([])\n const source = shallowRef(list)\n\n const state: Ref<UseVirtualListState> = ref({ start: 0, end: 10, current: 0, scale: 1 })\n\n return { state, source, currentList, size, containerRef }\n}\n\nfunction createGetViewCapacity<T>(state: UseVirtualListResources<T>['state'], source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize) {\n return (containerSize: number) => {\n const { start = 0, scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.ceil(containerSize / (itemSize * scale))\n\n let sum = 0\n let capacity = 0\n for (let i = start; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n capacity = i\n if (sum > containerSize)\n break\n }\n return capacity - start\n }\n}\n// 根据滚动条获取索引\nfunction createGetOffset<T>(source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize, state: UseVirtualListResources<T>['state']) {\n return (scrollDirection: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.floor(scrollDirection / (itemSize * scale)) + 1\n\n let sum = 0\n let offset = 0\n\n for (let i = 0; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n if (sum >= scrollDirection) {\n offset = i\n break\n }\n }\n return offset + 1\n }\n}\n\nfunction createCalculateRange<T>(type: 'horizontal' | 'vertical', overscan: number, getOffset: ReturnType<typeof createGetOffset>, getViewCapacity: ReturnType<typeof createGetViewCapacity>, { containerRef, state, currentList, source }: UseVirtualListResources<T>, updateTrigger) {\n return () => {\n const element = containerRef.value\n if (element) {\n const offset = getOffset(type === 'vertical' ? element.scrollTop : element.scrollLeft)\n const viewCapacity = getViewCapacity(type === 'vertical' ? element.clientHeight : element.clientWidth)\n\n const from = offset - overscan\n const to = offset + viewCapacity + overscan\n\n state.value = {\n start: from < 0 ? 0 : from,\n end: to > source.value.length\n ? source.value.length\n : to,\n current: offset - 1,\n scale: state.value.scale\n }\n currentList.value = source.value\n .slice(state.value.start, state.value.end)\n .map((ele, index) => ({\n data: ele,\n index: index + state.value.start\n }))\n updateTrigger(state.value)\n }\n }\n}\n// 获取距离\nfunction createGetDistance<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return (index: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number') {\n const size = index * (itemSize * scale)\n return Math.ceil(size)\n }\n\n const size = source.value\n .slice(0, index)\n .reduce((sum, _, i) => sum + itemSize(i) * scale, 0)\n\n return Math.ceil(size)\n }\n}\n\nfunction useWatchForSizes<T>(size: UseVirtualElementSizes, list: MaybeRef<T[]>, containerRef: Ref<HTMLElement | null>, calculateRange: () => void) {\n watch([size.width, size.height, list, containerRef], () => {\n calculateRange()\n })\n}\n// 获取总高度\nfunction createComputedTotalSize<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return computed(() => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return source.value.length * itemSize * scale\n\n return source.value.reduce((sum, _, index) => sum + itemSize(index) * scale, 0)\n })\n}\n\nconst scrollToDictionaryForElementScrollKey = {\n horizontal: 'scrollLeft',\n vertical: 'scrollTop'\n} as const\n\nfunction createScrollTo<T>(type: 'horizontal' | 'vertical', calculateRange: () => void, getDistance: ReturnType<typeof createGetDistance>, containerRef: UseVirtualListResources<T>['containerRef']) {\n return (index: number) => {\n if (containerRef.value) {\n containerRef.value[scrollToDictionaryForElementScrollKey[type]] = getDistance(index)\n calculateRange()\n }\n }\n}\n\nfunction useHorizontalVirtualList<T>(options: UseHorizontalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n const { state, source, currentList, size, containerRef } = resources\n const containerStyle: StyleValue = { overflowX: 'auto' }\n\n const { itemWidth, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemWidth)\n\n const getOffset = createGetOffset(source, itemWidth, state)\n\n const calculateRange = createCalculateRange('horizontal', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceLeft = createGetDistance(itemWidth, source, state)\n\n const offsetLeft = computed(() => getDistanceLeft(state.value.start))\n\n const totalWidth = createComputedTotalSize(itemWidth, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('horizontal', calculateRange, getDistanceLeft, containerRef)\n const scaleTo = (s: number) => {\n state.value.scale = s\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: '100%',\n width: `${totalWidth.value - offsetLeft.value}px`,\n marginLeft: `${offsetLeft.value}px`,\n display: 'flex',\n transform: `scale(${state.value.scale})`,\n transformOrigin: '0% 0%'\n // position: 'absolute',\n // left: '50%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n scrollTo,\n calculateRange,\n wrapperProps,\n containerStyle,\n currentList,\n containerRef\n }\n}\n\nfunction useVerticalVirtualList<T>(options: UseVerticalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n\n const { state, source, currentList, size, containerRef } = resources\n\n const containerStyle: StyleValue = { overflowY: 'auto' }\n\n const { itemHeight, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemHeight)\n\n const getOffset = createGetOffset(source, itemHeight, state)\n\n const calculateRange = createCalculateRange('vertical', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceTop = createGetDistance(itemHeight, source, state)\n\n const offsetTop = computed(() => getDistanceTop(state.value.start))\n\n const totalHeight = createComputedTotalSize(itemHeight, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('vertical', calculateRange, getDistanceTop, containerRef)\n const scaleTo = (s: number) => {\n // state.value.scale = s\n const element = containerRef.value\n if (element) {\n const { current } = state.value\n let offsetScroll = 0\n if (typeof itemHeight === 'number') {\n offsetScroll = current * (s * itemHeight - state.value.scale * itemHeight)\n }\n else {\n offsetScroll = source.value.slice(0, current).reduce((sum, _, i) => sum + s * itemHeight(i) - state.value.scale * itemHeight(i), 0)\n }\n element.scrollTop = element.scrollTop + offsetScroll >= 0 ? element.scrollTop + offsetScroll : 0\n state.value.scale = s\n }\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: `${totalHeight.value - offsetTop.value}px`,\n marginTop: `${offsetTop.value}px`,\n transform: `translateX(-50%) scale(${state.value.scale})`,\n transformOrigin: '50% 0%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n calculateRange,\n scrollTo,\n containerStyle,\n wrapperProps,\n currentList,\n containerRef\n }\n}\n"],"names":["useVirtualList","list","options","containerStyle","wrapperProps","scrollTo","calculateRange","currentList","containerRef","scaleTo","state","onUpdate","useVerticalVirtualList","useHorizontalVirtualList","useVirtualListResources","ref","size","useElementSize","source","shallowRef","createGetViewCapacity","itemSize","containerSize","start","scale","sum","capacity","i","createGetOffset","scrollDirection","offset","createCalculateRange","type","overscan","getOffset","getViewCapacity","updateTrigger","element","viewCapacity","from","to","ele","index","createGetDistance","_","useWatchForSizes","watch","createComputedTotalSize","computed","scrollToDictionaryForElementScrollKey","createScrollTo","getDistance","createEventHook","resources","itemWidth","getDistanceLeft","offsetLeft","totalWidth","s","itemHeight","getDistanceTop","offsetTop","totalHeight","current","offsetScroll"],"mappings":";;;AA6EgB,SAAAA,EAAwBC,GAAqBC,GAAyD;AACpH,QAAM,EAAE,gBAAAC,GAAgB,cAAAC,GAAc,UAAAC,GAAU,gBAAAC,GAAgB,aAAAC,GAAa,cAAAC,GAAc,SAAAC,GAAS,OAAAC,GAAO,UAAAC,EAAa,IAAA,gBAAgBT,IACpIU,EAAuBV,GAASD,CAAI,IACpCY,EAAyBX,GAASD,CAAI;AAEnC,SAAA;AAAA,IACL,UAAAU;AAAA,IACA,OAAAD;AAAA,IACA,SAAAD;AAAA,IACA,MAAMF;AAAA,IACN,UAAAF;AAAA,IACA,gBAAgB;AAAA,MACd,KAAKG;AAAA,MACL,UAAU,MAAM;AACC,QAAAF;MACjB;AAAA,MACA,OAAOH;AAAA,IACT;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;AAsBA,SAASU,EAA2Bb,GAAiD;AAC7E,QAAAO,IAAeO,EAAwB,IAAI,GAC3CC,IAAOC,EAAeT,CAAY,GAElCD,IAA4CQ,EAAI,CAAA,CAAE,GAClDG,IAASC,EAAWlB,CAAI;AAI9B,SAAO,EAAE,OAF+Bc,EAAI,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,GAAG,OAAO,EAAG,CAAA,GAEvE,QAAAG,GAAQ,aAAAX,GAAa,MAAAS,GAAM,cAAAR,EAAa;AAC1D;AAEA,SAASY,EAAyBV,GAA4CQ,GAA8CG,GAAkC;AA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S;AACL,YAAA,EAAE,SAAA0B,EAAQ,IAAIrD,EAAM;AAC1B,UAAIsD,IAAe;AACf,MAAA,OAAOL,KAAe,WACxBK,IAAeD,KAAWL,IAAIC,IAAajD,EAAM,MAAM,QAAQiD,KAGhDK,IAAA9C,EAAO,MAAM,MAAM,GAAG6C,CAAO,EAAE,OAAO,CAACtC,GAAKmB,GAAGjB,MAAMF,IAAMiC,IAAIC,EAAWhC,CAAC,IAAIjB,EAAM,MAAM,QAAQiD,EAAWhC,CAAC,GAAG,CAAC,GAEpIU,EAAQ,YAAYA,EAAQ,YAAY2B,KAAgB,IAAI3B,EAAQ,YAAY2B,IAAe,GAC/FtD,EAAM,MAAM,QAAQgD;AAAA,IACtB;AAAA,EAAA,GAEItD,IAAe4C,EAAS,OACrB;AAAA,IACL,OAAO;AAAA,MACL,QAAQ,GAAGc,EAAY,QAAQD,EAAU,KAAK;AAAA,MAC9C,WAAW,GAAGA,EAAU,KAAK;AAAA,MAC7B,WAAW,0BAA0BnD,EAAM,MAAM,KAAK;AAAA,MACtD,iBAAiB;AAAA,IACnB;AAAA,EAAA,EAEH;AAEM,SAAA;AAAA,IACL,UAAAC;AAAA,IACA,OAAAD;AAAA,IACA,SAAAD;AAAA,IACA,gBAAAH;AAAA,IACA,UAAAD;AAAA,IACA,gBAAAF;AAAA,IACA,cAAAC;AAAA,IACA,aAAAG;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("@vueuse/shared"),f=require("vue"),G=require("@vueuse/core");function S(r,t){const{containerStyle:a,wrapperProps:o,scrollTo:n,calculateRange:e,currentList:c,containerRef:l,scaleTo:u,state:s,onUpdate:v}="itemHeight"in t?F(t,r):_(t,r);return{onUpdate:v,state:s,scaleTo:u,list:c,scrollTo:n,containerProps:{ref:l,onScroll:()=>{e()},style:a},wrapperProps:o}}function x(r){const t=f.ref(null),a=G.useElementSize(t),o=f.ref([]),n=f.shallowRef(r);return{state:f.ref({start:0,end:10,current:0,scale:1}),source:n,currentList:o,size:a,containerRef:t}}function M(r,t,a){return o=>{const{start:n=0,scale:e=1}=r.value;if(typeof a=="number")return Math.ceil(o/(a*e));let c=0,l=0;for(let u=n;u<t.value.length;u++){const s=a(u)*e;if(c+=s,l=u,c>o)break}return l-n}}function P(r,t,a){return o=>{const{scale:n=1}=a.value;if(typeof t=="number")return Math.floor(o/(t*n))+1;let e=0,c=0;for(let l=0;l<r.value.length;l++){const u=t(l)*n;if(e+=u,e>=o){c=l;break}}return c+1}}function k(r,t,a,o,{containerRef:n,state:e,currentList:c,source:l},u){return()=>{const s=n.value;if(s){const v=a(r==="vertical"?s.scrollTop:s.scrollLeft),i=o(r==="vertical"?s.clientHeight:s.clientWidth),g=v-t,h=v+i+t;e.value={start:g<0?0:g,end:h>l.value.length?l.value.length:h,current:v,scale:e.value.scale},c.value=l.value.slice(e.value.start,e.value.end).map((d,p)=>({data:d,index:p+e.value.start})),u(e.value)}}}function z(r,t,a){return o=>{const{scale:n=1}=a.value;if(typeof r=="number"){const c=o*(r*n);return Math.ceil(c)}const e=t.value.slice(0,o).reduce((c,l,u)=>c+r(u)*n,0);return Math.ceil(e)}}function E(r,t,a,o){f.watch([r.width,r.height,t,a],()=>{o()})}function W(r,t,a){return f.computed(()=>{const{scale:o=1}=a.value;return typeof r=="number"?t.value.length*r*o:t.value.reduce((n,e,c)=>n+r(c)*o,0)})}const U={horizontal:"scrollLeft",vertical:"scrollTop"};function q(r,t,a,o){return n=>{o.value&&(o.value[U[r]]=a(n),t())}}function _(r,t){const{on:a,trigger:o}=$.createEventHook(),n=x(t),{state:e,source:c,currentList:l,size:u,containerRef:s}=n,v={overflowX:"auto"},{itemWidth:i,overscan:g=5}=r,h=M(e,c,i),d=P(c,i,e),p=k("horizontal",g,d,h,n,o),m=z(i,c,e),y=f.computed(()=>m(e.value.start)),b=W(i,c,e);E(u,t,s,p);const R=q("horizontal",p,m,s),V=T=>{e.value.scale=T},H=f.computed(()=>({style:{height:"100%",width:`${b.value-y.value}px`,marginLeft:`${y.value}px`,display:"flex",transform:`scale(${e.value.scale})`,transformOrigin:"0% 0%"}}));return{onUpdate:a,state:e,scaleTo:V,scrollTo:R,calculateRange:p,wrapperProps:H,containerStyle:v,currentList:l,containerRef:s}}function F(r,t){const{on:a,trigger:o}=$.createEventHook(),n=x(t),{state:e,source:c,currentList:l,size:u,containerRef:s}=n,v={overflowY:"auto"},{itemHeight:i,overscan:g=5}=r,h=M(e,c,i),d=P(c,i,e),p=k("vertical",g,d,h,n,o),m=z(i,c,e),y=f.computed(()=>m(e.value.start)),b=W(i,c,e);E(u,t,s,p);const R=q("vertical",p,m,s),V=T=>{const L=s.value;if(L){const{current:C}=e.value;let w=0;typeof i=="number"?w=C*(T*i-e.value.scale*i):w=c.value.slice(0,C).reduce((D,X,O)=>D+T*i(O)-e.value.scale*i(O),0),L.scrollTop=L.scrollTop+w>=0?L.scrollTop+w:0,e.value.scale=T}},H=f.computed(()=>({style:{height:`${b.value-y.value}px`,marginTop:`${y.value}px`,transform:`translateX(-50%) scale(${e.value.scale})`,transformOrigin:"50% 0%"}}));return{onUpdate:a,state:e,scaleTo:V,calculateRange:p,scrollTo:R,containerStyle:v,wrapperProps:H,currentList:l,containerRef:s}}exports.useVirtualList=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("@vueuse/shared"),f=require("vue"),G=require("@vueuse/core");function S(r,t){const{containerStyle:a,wrapperProps:o,scrollTo:n,calculateRange:e,currentList:c,containerRef:l,scaleTo:u,state:s,onUpdate:v}="itemHeight"in t?F(t,r):_(t,r);return{onUpdate:v,state:s,scaleTo:u,list:c,scrollTo:n,containerProps:{ref:l,onScroll:()=>{e()},style:a},wrapperProps:o}}function x(r){const t=f.ref(null),a=G.useElementSize(t),o=f.ref([]),n=f.shallowRef(r);return{state:f.ref({start:0,end:10,current:0,scale:1}),source:n,currentList:o,size:a,containerRef:t}}function M(r,t,a){return o=>{const{start:n=0,scale:e=1}=r.value;if(typeof a=="number")return Math.ceil(o/(a*e));let c=0,l=0;for(let u=n;u<t.value.length;u++){const s=a(u)*e;if(c+=s,l=u,c>o)break}return l-n}}function P(r,t,a){return o=>{const{scale:n=1}=a.value;if(typeof t=="number")return Math.floor(o/(t*n))+1;let e=0,c=0;for(let l=0;l<r.value.length;l++){const u=t(l)*n;if(e+=u,e>=o){c=l;break}}return c+1}}function k(r,t,a,o,{containerRef:n,state:e,currentList:c,source:l},u){return()=>{const s=n.value;if(s){const v=a(r==="vertical"?s.scrollTop:s.scrollLeft),i=o(r==="vertical"?s.clientHeight:s.clientWidth),g=v-t,h=v+i+t;e.value={start:g<0?0:g,end:h>l.value.length?l.value.length:h,current:v-1,scale:e.value.scale},c.value=l.value.slice(e.value.start,e.value.end).map((d,p)=>({data:d,index:p+e.value.start})),u(e.value)}}}function z(r,t,a){return o=>{const{scale:n=1}=a.value;if(typeof r=="number"){const c=o*(r*n);return Math.ceil(c)}const e=t.value.slice(0,o).reduce((c,l,u)=>c+r(u)*n,0);return Math.ceil(e)}}function E(r,t,a,o){f.watch([r.width,r.height,t,a],()=>{o()})}function W(r,t,a){return f.computed(()=>{const{scale:o=1}=a.value;return typeof r=="number"?t.value.length*r*o:t.value.reduce((n,e,c)=>n+r(c)*o,0)})}const U={horizontal:"scrollLeft",vertical:"scrollTop"};function q(r,t,a,o){return n=>{o.value&&(o.value[U[r]]=a(n),t())}}function _(r,t){const{on:a,trigger:o}=$.createEventHook(),n=x(t),{state:e,source:c,currentList:l,size:u,containerRef:s}=n,v={overflowX:"auto"},{itemWidth:i,overscan:g=5}=r,h=M(e,c,i),d=P(c,i,e),p=k("horizontal",g,d,h,n,o),m=z(i,c,e),y=f.computed(()=>m(e.value.start)),b=W(i,c,e);E(u,t,s,p);const R=q("horizontal",p,m,s),V=T=>{e.value.scale=T},H=f.computed(()=>({style:{height:"100%",width:`${b.value-y.value}px`,marginLeft:`${y.value}px`,display:"flex",transform:`scale(${e.value.scale})`,transformOrigin:"0% 0%"}}));return{onUpdate:a,state:e,scaleTo:V,scrollTo:R,calculateRange:p,wrapperProps:H,containerStyle:v,currentList:l,containerRef:s}}function F(r,t){const{on:a,trigger:o}=$.createEventHook(),n=x(t),{state:e,source:c,currentList:l,size:u,containerRef:s}=n,v={overflowY:"auto"},{itemHeight:i,overscan:g=5}=r,h=M(e,c,i),d=P(c,i,e),p=k("vertical",g,d,h,n,o),m=z(i,c,e),y=f.computed(()=>m(e.value.start)),b=W(i,c,e);E(u,t,s,p);const R=q("vertical",p,m,s),V=T=>{const L=s.value;if(L){const{current:C}=e.value;let w=0;typeof i=="number"?w=C*(T*i-e.value.scale*i):w=c.value.slice(0,C).reduce((D,X,O)=>D+T*i(O)-e.value.scale*i(O),0),L.scrollTop=L.scrollTop+w>=0?L.scrollTop+w:0,e.value.scale=T}},H=f.computed(()=>({style:{height:`${b.value-y.value}px`,marginTop:`${y.value}px`,transform:`translateX(-50%) scale(${e.value.scale})`,transformOrigin:"50% 0%"}}));return{onUpdate:a,state:e,scaleTo:V,calculateRange:p,scrollTo:R,containerStyle:v,wrapperProps:H,currentList:l,containerRef:s}}exports.useVirtualList=S;
2
2
  //# sourceMappingURL=useVirtualList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualList.js","sources":["../../../../../components/scale-virtual-list/hooks/useVirtualList.ts"],"sourcesContent":["import { type EventHookOn, type MaybeRef, createEventHook } from '@vueuse/shared'\nimport type { ComputedRef, Ref, ShallowRef, StyleValue } from 'vue'\nimport { computed, ref, shallowRef, watch } from 'vue'\nimport { useElementSize } from '@vueuse/core'\n\nexport interface UseVirtualListState { start: number, end: number, current: number, scale: number }\n\ntype RefState = Ref<UseVirtualListState>\ntype UseVirtualListItemSize = number | ((index: number) => number)\n\nexport interface UseHorizontalVirtualListOptions extends UseVirtualListOptionsBase {\n\n /**\n * item width, accept a pixel value or a function that returns the width\n *\n * @default 0\n */\n itemWidth: UseVirtualListItemSize\n\n}\n\nexport interface UseVerticalVirtualListOptions extends UseVirtualListOptionsBase {\n /**\n * item height, accept a pixel value or a function that returns the height\n *\n * @default 0\n */\n itemHeight: UseVirtualListItemSize\n}\n\nexport interface UseVirtualListOptionsBase {\n /**\n * the extra buffer items outside of the view area\n *\n * @default 5\n */\n overscan?: number\n}\n\nexport type UseVirtualListOptions = UseHorizontalVirtualListOptions | UseVerticalVirtualListOptions\n\nexport interface UseVirtualListItem<T> {\n data: T\n index: number\n}\n\nexport interface UseVirtualListReturn<T> {\n onUpdate: EventHookOn<UseVirtualListState | null>\n state: RefState\n list: Ref<UseVirtualListItem<T>[]>\n scrollTo: (index: number) => void\n scaleTo: (s: number) => void\n containerProps: {\n ref: Ref<HTMLElement | null>\n onScroll: () => void\n style: StyleValue\n }\n wrapperProps: ComputedRef<{\n style: {\n height: string\n marginTop: string\n transform: string\n transformOrigin: string\n } | {\n width: string\n height: string\n marginLeft: string\n display: string\n transform: string\n transformOrigin: string\n }\n }>\n}\n\n/**\n * Please consider using [`vue-virtual-scroller`](https://github.com/Akryum/vue-virtual-scroller) if you are looking for more features.\n */\nexport function useVirtualList<T = any>(list: MaybeRef<T[]>, options: UseVirtualListOptions): UseVirtualListReturn<T> {\n const { containerStyle, wrapperProps, scrollTo, calculateRange, currentList, containerRef, scaleTo, state, onUpdate } = 'itemHeight' in options\n ? useVerticalVirtualList(options, list)\n : useHorizontalVirtualList(options, list)\n\n return {\n onUpdate,\n state,\n scaleTo,\n list: currentList,\n scrollTo,\n containerProps: {\n ref: containerRef,\n onScroll: () => {\n calculateRange()\n },\n style: containerStyle\n },\n wrapperProps\n }\n}\n\ntype UseVirtualListContainerRef = Ref<HTMLElement | null>\n\ninterface UseVirtualElementSizes {\n width: Ref<number>\n height: Ref<number>\n}\n\ntype UseVirtualListArray<T> = UseVirtualListItem<T>[]\ntype UseVirtualListRefArray<T> = Ref<UseVirtualListArray<T>>\n\ntype UseVirtualListSource<T> = Ref<T[]> | ShallowRef<T[]>\n\ninterface UseVirtualListResources<T> {\n state: RefState\n source: UseVirtualListSource<T>\n currentList: UseVirtualListRefArray<T>\n size: UseVirtualElementSizes\n containerRef: UseVirtualListContainerRef\n}\n\nfunction useVirtualListResources<T>(list: MaybeRef<T[]>): UseVirtualListResources<T> {\n const containerRef = ref<HTMLElement | null>(null)\n const size = useElementSize(containerRef)\n\n const currentList: Ref<UseVirtualListItem<T>[]> = ref([])\n const source = shallowRef(list)\n\n const state: Ref<UseVirtualListState> = ref({ start: 0, end: 10, current: 0, scale: 1 })\n\n return { state, source, currentList, size, containerRef }\n}\n\nfunction createGetViewCapacity<T>(state: UseVirtualListResources<T>['state'], source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize) {\n return (containerSize: number) => {\n const { start = 0, scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.ceil(containerSize / (itemSize * scale))\n\n let sum = 0\n let capacity = 0\n for (let i = start; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n capacity = i\n if (sum > containerSize)\n break\n }\n return capacity - start\n }\n}\n// 根据滚动条获取索引\nfunction createGetOffset<T>(source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize, state: UseVirtualListResources<T>['state']) {\n return (scrollDirection: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.floor(scrollDirection / (itemSize * scale)) + 1\n\n let sum = 0\n let offset = 0\n\n for (let i = 0; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n if (sum >= scrollDirection) {\n offset = i\n break\n }\n }\n return offset + 1\n }\n}\n\nfunction createCalculateRange<T>(type: 'horizontal' | 'vertical', overscan: number, getOffset: ReturnType<typeof createGetOffset>, getViewCapacity: ReturnType<typeof createGetViewCapacity>, { containerRef, state, currentList, source }: UseVirtualListResources<T>, updateTrigger) {\n return () => {\n const element = containerRef.value\n if (element) {\n const offset = getOffset(type === 'vertical' ? element.scrollTop : element.scrollLeft)\n const viewCapacity = getViewCapacity(type === 'vertical' ? element.clientHeight : element.clientWidth)\n\n const from = offset - overscan\n const to = offset + viewCapacity + overscan\n\n state.value = {\n start: from < 0 ? 0 : from,\n end: to > source.value.length\n ? source.value.length\n : to,\n current: offset,\n scale: state.value.scale\n }\n currentList.value = source.value\n .slice(state.value.start, state.value.end)\n .map((ele, index) => ({\n data: ele,\n index: index + state.value.start\n }))\n updateTrigger(state.value)\n }\n }\n}\n// 获取距离\nfunction createGetDistance<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return (index: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number') {\n const size = index * (itemSize * scale)\n return Math.ceil(size)\n }\n\n const size = source.value\n .slice(0, index)\n .reduce((sum, _, i) => sum + itemSize(i) * scale, 0)\n\n return Math.ceil(size)\n }\n}\n\nfunction useWatchForSizes<T>(size: UseVirtualElementSizes, list: MaybeRef<T[]>, containerRef: Ref<HTMLElement | null>, calculateRange: () => void) {\n watch([size.width, size.height, list, containerRef], () => {\n calculateRange()\n })\n}\n// 获取总高度\nfunction createComputedTotalSize<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return computed(() => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return source.value.length * itemSize * scale\n\n return source.value.reduce((sum, _, index) => sum + itemSize(index) * scale, 0)\n })\n}\n\nconst scrollToDictionaryForElementScrollKey = {\n horizontal: 'scrollLeft',\n vertical: 'scrollTop'\n} as const\n\nfunction createScrollTo<T>(type: 'horizontal' | 'vertical', calculateRange: () => void, getDistance: ReturnType<typeof createGetDistance>, containerRef: UseVirtualListResources<T>['containerRef']) {\n return (index: number) => {\n if (containerRef.value) {\n containerRef.value[scrollToDictionaryForElementScrollKey[type]] = getDistance(index)\n calculateRange()\n }\n }\n}\n\nfunction useHorizontalVirtualList<T>(options: UseHorizontalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n const { state, source, currentList, size, containerRef } = resources\n const containerStyle: StyleValue = { overflowX: 'auto' }\n\n const { itemWidth, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemWidth)\n\n const getOffset = createGetOffset(source, itemWidth, state)\n\n const calculateRange = createCalculateRange('horizontal', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceLeft = createGetDistance(itemWidth, source, state)\n\n const offsetLeft = computed(() => getDistanceLeft(state.value.start))\n\n const totalWidth = createComputedTotalSize(itemWidth, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('horizontal', calculateRange, getDistanceLeft, containerRef)\n const scaleTo = (s: number) => {\n state.value.scale = s\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: '100%',\n width: `${totalWidth.value - offsetLeft.value}px`,\n marginLeft: `${offsetLeft.value}px`,\n display: 'flex',\n transform: `scale(${state.value.scale})`,\n transformOrigin: '0% 0%'\n // position: 'absolute',\n // left: '50%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n scrollTo,\n calculateRange,\n wrapperProps,\n containerStyle,\n currentList,\n containerRef\n }\n}\n\nfunction useVerticalVirtualList<T>(options: UseVerticalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n\n const { state, source, currentList, size, containerRef } = resources\n\n const containerStyle: StyleValue = { overflowY: 'auto' }\n\n const { itemHeight, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemHeight)\n\n const getOffset = createGetOffset(source, itemHeight, state)\n\n const calculateRange = createCalculateRange('vertical', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceTop = createGetDistance(itemHeight, source, state)\n\n const offsetTop = computed(() => getDistanceTop(state.value.start))\n\n const totalHeight = createComputedTotalSize(itemHeight, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('vertical', calculateRange, getDistanceTop, containerRef)\n const scaleTo = (s: number) => {\n // state.value.scale = s\n const element = containerRef.value\n if (element) {\n const { current } = state.value\n let offsetScroll = 0\n if (typeof itemHeight === 'number') {\n offsetScroll = current * (s * itemHeight - state.value.scale * itemHeight)\n }\n else {\n offsetScroll = source.value.slice(0, current).reduce((sum, _, i) => sum + s * itemHeight(i) - state.value.scale * itemHeight(i), 0)\n }\n element.scrollTop = element.scrollTop + offsetScroll >= 0 ? element.scrollTop + offsetScroll : 0\n state.value.scale = s\n }\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: `${totalHeight.value - offsetTop.value}px`,\n marginTop: `${offsetTop.value}px`,\n transform: `translateX(-50%) scale(${state.value.scale})`,\n transformOrigin: '50% 0%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n calculateRange,\n scrollTo,\n containerStyle,\n wrapperProps,\n currentList,\n containerRef\n }\n}\n"],"names":["useVirtualList","list","options","containerStyle","wrapperProps","scrollTo","calculateRange","currentList","containerRef","scaleTo","state","onUpdate","useVerticalVirtualList","useHorizontalVirtualList","useVirtualListResources","ref","size","useElementSize","source","shallowRef","createGetViewCapacity","itemSize","containerSize","start","scale","sum","capacity","i","createGetOffset","scrollDirection","offset","createCalculateRange","type","overscan","getOffset","getViewCapacity","updateTrigger","element","viewCapacity","from","to","ele","index","createGetDistance","_","useWatchForSizes","watch","createComputedTotalSize","computed","scrollToDictionaryForElementScrollKey","createScrollTo","getDistance","createEventHook","resources","itemWidth","getDistanceLeft","offsetLeft","totalWidth","s","itemHeight","getDistanceTop","offsetTop","totalHeight","current","offsetScroll"],"mappings":"6JA6EgB,SAAAA,EAAwBC,EAAqBC,EAAyD,CACpH,KAAM,CAAE,eAAAC,EAAgB,aAAAC,EAAc,SAAAC,EAAU,eAAAC,EAAgB,YAAAC,EAAa,aAAAC,EAAc,QAAAC,EAAS,M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wB,EAAiBjB,EAAkBgB,EAAYzC,EAAQR,CAAK,EAE5DmD,EAAYb,EAAAA,SAAS,IAAMY,EAAelD,EAAM,MAAM,KAAK,CAAC,EAE5DoD,EAAcf,EAAwBY,EAAYzC,EAAQR,CAAK,EAEpDmC,EAAA7B,EAAMf,EAAMO,EAAcF,CAAc,EAEzD,MAAMD,EAAW6C,EAAe,WAAY5C,EAAgBsD,EAAgBpD,CAAY,EAClFC,EAAWiD,GAAc,CAE7B,MAAMrB,EAAU7B,EAAa,MAC7B,GAAI6B,EAAS,CACL,KAAA,CAAE,QAAA0B,CAAQ,EAAIrD,EAAM,MAC1B,IAAIsD,EAAe,EACf,OAAOL,GAAe,SACxBK,EAAeD,GAAWL,EAAIC,EAAajD,EAAM,MAAM,MAAQiD,GAGhDK,EAAA9C,EAAO,MAAM,MAAM,EAAG6C,CAAO,EAAE,OAAO,CAACtC,EAAKmB,EAAGjB,IAAMF,EAAMiC,EAAIC,EAAWhC,CAAC,EAAIjB,EAAM,MAAM,MAAQiD,EAAWhC,CAAC,EAAG,CAAC,EAEpIU,EAAQ,UAAYA,EAAQ,UAAY2B,GAAgB,EAAI3B,EAAQ,UAAY2B,EAAe,EAC/FtD,EAAM,MAAM,MAAQgD,CACtB,CAAA,EAEItD,EAAe4C,EAAAA,SAAS,KACrB,CACL,MAAO,CACL,OAAQ,GAAGc,EAAY,MAAQD,EAAU,KAAK,KAC9C,UAAW,GAAGA,EAAU,KAAK,KAC7B,UAAW,0BAA0BnD,EAAM,MAAM,KAAK,IACtD,gBAAiB,QACnB,CAAA,EAEH,EAEM,MAAA,CACL,SAAAC,EACA,MAAAD,EACA,QAAAD,EACA,eAAAH,EACA,SAAAD,EACA,eAAAF,EACA,aAAAC,EACA,YAAAG,EACA,aAAAC,CAAA,CAEJ"}
1
+ {"version":3,"file":"useVirtualList.js","sources":["../../../../../components/scale-virtual-list/hooks/useVirtualList.ts"],"sourcesContent":["import { type EventHookOn, type MaybeRef, createEventHook } from '@vueuse/shared'\nimport type { ComputedRef, Ref, ShallowRef, StyleValue } from 'vue'\nimport { computed, ref, shallowRef, watch } from 'vue'\nimport { useElementSize } from '@vueuse/core'\n\nexport interface UseVirtualListState { start: number, end: number, current: number, scale: number }\n\ntype RefState = Ref<UseVirtualListState>\ntype UseVirtualListItemSize = number | ((index: number) => number)\n\nexport interface UseHorizontalVirtualListOptions extends UseVirtualListOptionsBase {\n\n /**\n * item width, accept a pixel value or a function that returns the width\n *\n * @default 0\n */\n itemWidth: UseVirtualListItemSize\n\n}\n\nexport interface UseVerticalVirtualListOptions extends UseVirtualListOptionsBase {\n /**\n * item height, accept a pixel value or a function that returns the height\n *\n * @default 0\n */\n itemHeight: UseVirtualListItemSize\n}\n\nexport interface UseVirtualListOptionsBase {\n /**\n * the extra buffer items outside of the view area\n *\n * @default 5\n */\n overscan?: number\n}\n\nexport type UseVirtualListOptions = UseHorizontalVirtualListOptions | UseVerticalVirtualListOptions\n\nexport interface UseVirtualListItem<T> {\n data: T\n index: number\n}\n\nexport interface UseVirtualListReturn<T> {\n onUpdate: EventHookOn<UseVirtualListState | null>\n state: RefState\n list: Ref<UseVirtualListItem<T>[]>\n scrollTo: (index: number) => void\n scaleTo: (s: number) => void\n containerProps: {\n ref: Ref<HTMLElement | null>\n onScroll: () => void\n style: StyleValue\n }\n wrapperProps: ComputedRef<{\n style: {\n height: string\n marginTop: string\n transform: string\n transformOrigin: string\n } | {\n width: string\n height: string\n marginLeft: string\n display: string\n transform: string\n transformOrigin: string\n }\n }>\n}\n\n/**\n * Please consider using [`vue-virtual-scroller`](https://github.com/Akryum/vue-virtual-scroller) if you are looking for more features.\n */\nexport function useVirtualList<T = any>(list: MaybeRef<T[]>, options: UseVirtualListOptions): UseVirtualListReturn<T> {\n const { containerStyle, wrapperProps, scrollTo, calculateRange, currentList, containerRef, scaleTo, state, onUpdate } = 'itemHeight' in options\n ? useVerticalVirtualList(options, list)\n : useHorizontalVirtualList(options, list)\n\n return {\n onUpdate,\n state,\n scaleTo,\n list: currentList,\n scrollTo,\n containerProps: {\n ref: containerRef,\n onScroll: () => {\n calculateRange()\n },\n style: containerStyle\n },\n wrapperProps\n }\n}\n\ntype UseVirtualListContainerRef = Ref<HTMLElement | null>\n\ninterface UseVirtualElementSizes {\n width: Ref<number>\n height: Ref<number>\n}\n\ntype UseVirtualListArray<T> = UseVirtualListItem<T>[]\ntype UseVirtualListRefArray<T> = Ref<UseVirtualListArray<T>>\n\ntype UseVirtualListSource<T> = Ref<T[]> | ShallowRef<T[]>\n\ninterface UseVirtualListResources<T> {\n state: RefState\n source: UseVirtualListSource<T>\n currentList: UseVirtualListRefArray<T>\n size: UseVirtualElementSizes\n containerRef: UseVirtualListContainerRef\n}\n\nfunction useVirtualListResources<T>(list: MaybeRef<T[]>): UseVirtualListResources<T> {\n const containerRef = ref<HTMLElement | null>(null)\n const size = useElementSize(containerRef)\n\n const currentList: Ref<UseVirtualListItem<T>[]> = ref([])\n const source = shallowRef(list)\n\n const state: Ref<UseVirtualListState> = ref({ start: 0, end: 10, current: 0, scale: 1 })\n\n return { state, source, currentList, size, containerRef }\n}\n\nfunction createGetViewCapacity<T>(state: UseVirtualListResources<T>['state'], source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize) {\n return (containerSize: number) => {\n const { start = 0, scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.ceil(containerSize / (itemSize * scale))\n\n let sum = 0\n let capacity = 0\n for (let i = start; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n capacity = i\n if (sum > containerSize)\n break\n }\n return capacity - start\n }\n}\n// 根据滚动条获取索引\nfunction createGetOffset<T>(source: UseVirtualListResources<T>['source'], itemSize: UseVirtualListItemSize, state: UseVirtualListResources<T>['state']) {\n return (scrollDirection: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return Math.floor(scrollDirection / (itemSize * scale)) + 1\n\n let sum = 0\n let offset = 0\n\n for (let i = 0; i < source.value.length; i++) {\n const size = itemSize(i) * scale\n sum += size\n if (sum >= scrollDirection) {\n offset = i\n break\n }\n }\n return offset + 1\n }\n}\n\nfunction createCalculateRange<T>(type: 'horizontal' | 'vertical', overscan: number, getOffset: ReturnType<typeof createGetOffset>, getViewCapacity: ReturnType<typeof createGetViewCapacity>, { containerRef, state, currentList, source }: UseVirtualListResources<T>, updateTrigger) {\n return () => {\n const element = containerRef.value\n if (element) {\n const offset = getOffset(type === 'vertical' ? element.scrollTop : element.scrollLeft)\n const viewCapacity = getViewCapacity(type === 'vertical' ? element.clientHeight : element.clientWidth)\n\n const from = offset - overscan\n const to = offset + viewCapacity + overscan\n\n state.value = {\n start: from < 0 ? 0 : from,\n end: to > source.value.length\n ? source.value.length\n : to,\n current: offset - 1,\n scale: state.value.scale\n }\n currentList.value = source.value\n .slice(state.value.start, state.value.end)\n .map((ele, index) => ({\n data: ele,\n index: index + state.value.start\n }))\n updateTrigger(state.value)\n }\n }\n}\n// 获取距离\nfunction createGetDistance<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return (index: number) => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number') {\n const size = index * (itemSize * scale)\n return Math.ceil(size)\n }\n\n const size = source.value\n .slice(0, index)\n .reduce((sum, _, i) => sum + itemSize(i) * scale, 0)\n\n return Math.ceil(size)\n }\n}\n\nfunction useWatchForSizes<T>(size: UseVirtualElementSizes, list: MaybeRef<T[]>, containerRef: Ref<HTMLElement | null>, calculateRange: () => void) {\n watch([size.width, size.height, list, containerRef], () => {\n calculateRange()\n })\n}\n// 获取总高度\nfunction createComputedTotalSize<T>(itemSize: UseVirtualListItemSize, source: UseVirtualListResources<T>['source'], state: UseVirtualListResources<T>['state']) {\n return computed(() => {\n const { scale = 1 } = state.value\n if (typeof itemSize === 'number')\n return source.value.length * itemSize * scale\n\n return source.value.reduce((sum, _, index) => sum + itemSize(index) * scale, 0)\n })\n}\n\nconst scrollToDictionaryForElementScrollKey = {\n horizontal: 'scrollLeft',\n vertical: 'scrollTop'\n} as const\n\nfunction createScrollTo<T>(type: 'horizontal' | 'vertical', calculateRange: () => void, getDistance: ReturnType<typeof createGetDistance>, containerRef: UseVirtualListResources<T>['containerRef']) {\n return (index: number) => {\n if (containerRef.value) {\n containerRef.value[scrollToDictionaryForElementScrollKey[type]] = getDistance(index)\n calculateRange()\n }\n }\n}\n\nfunction useHorizontalVirtualList<T>(options: UseHorizontalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n const { state, source, currentList, size, containerRef } = resources\n const containerStyle: StyleValue = { overflowX: 'auto' }\n\n const { itemWidth, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemWidth)\n\n const getOffset = createGetOffset(source, itemWidth, state)\n\n const calculateRange = createCalculateRange('horizontal', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceLeft = createGetDistance(itemWidth, source, state)\n\n const offsetLeft = computed(() => getDistanceLeft(state.value.start))\n\n const totalWidth = createComputedTotalSize(itemWidth, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('horizontal', calculateRange, getDistanceLeft, containerRef)\n const scaleTo = (s: number) => {\n state.value.scale = s\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: '100%',\n width: `${totalWidth.value - offsetLeft.value}px`,\n marginLeft: `${offsetLeft.value}px`,\n display: 'flex',\n transform: `scale(${state.value.scale})`,\n transformOrigin: '0% 0%'\n // position: 'absolute',\n // left: '50%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n scrollTo,\n calculateRange,\n wrapperProps,\n containerStyle,\n currentList,\n containerRef\n }\n}\n\nfunction useVerticalVirtualList<T>(options: UseVerticalVirtualListOptions, list: MaybeRef<T[]>) {\n const { on: onUpdate, trigger: updateTrigger } = createEventHook()\n const resources = useVirtualListResources(list)\n\n const { state, source, currentList, size, containerRef } = resources\n\n const containerStyle: StyleValue = { overflowY: 'auto' }\n\n const { itemHeight, overscan = 5 } = options\n\n const getViewCapacity = createGetViewCapacity(state, source, itemHeight)\n\n const getOffset = createGetOffset(source, itemHeight, state)\n\n const calculateRange = createCalculateRange('vertical', overscan, getOffset, getViewCapacity, resources, updateTrigger)\n\n const getDistanceTop = createGetDistance(itemHeight, source, state)\n\n const offsetTop = computed(() => getDistanceTop(state.value.start))\n\n const totalHeight = createComputedTotalSize(itemHeight, source, state)\n\n useWatchForSizes(size, list, containerRef, calculateRange)\n\n const scrollTo = createScrollTo('vertical', calculateRange, getDistanceTop, containerRef)\n const scaleTo = (s: number) => {\n // state.value.scale = s\n const element = containerRef.value\n if (element) {\n const { current } = state.value\n let offsetScroll = 0\n if (typeof itemHeight === 'number') {\n offsetScroll = current * (s * itemHeight - state.value.scale * itemHeight)\n }\n else {\n offsetScroll = source.value.slice(0, current).reduce((sum, _, i) => sum + s * itemHeight(i) - state.value.scale * itemHeight(i), 0)\n }\n element.scrollTop = element.scrollTop + offsetScroll >= 0 ? element.scrollTop + offsetScroll : 0\n state.value.scale = s\n }\n }\n const wrapperProps = computed(() => {\n return {\n style: {\n height: `${totalHeight.value - offsetTop.value}px`,\n marginTop: `${offsetTop.value}px`,\n transform: `translateX(-50%) scale(${state.value.scale})`,\n transformOrigin: '50% 0%'\n }\n }\n })\n\n return {\n onUpdate,\n state,\n scaleTo,\n calculateRange,\n scrollTo,\n containerStyle,\n wrapperProps,\n currentList,\n containerRef\n }\n}\n"],"names":["useVirtualList","list","options","containerStyle","wrapperProps","scrollTo","calculateRange","currentList","containerRef","scaleTo","state","onUpdate","useVerticalVirtualList","useHorizontalVirtualList","useVirtualListResources","ref","size","useElementSize","source","shallowRef","createGetViewCapacity","itemSize","containerSize","start","scale","sum","capacity","i","createGetOffset","scrollDirection","offset","createCalculateRange","type","overscan","getOffset","getViewCapacity","updateTrigger","element","viewCapacity","from","to","ele","index","createGetDistance","_","useWatchForSizes","watch","createComputedTotalSize","computed","scrollToDictionaryForElementScrollKey","createScrollTo","getDistance","createEventHook","resources","itemWidth","getDistanceLeft","offsetLeft","totalWidth","s","itemHeight","getDistanceTop","offsetTop","totalHeight","current","offsetScroll"],"mappings":"6JA6EgB,SAAAA,EAAwBC,EAAqBC,EAAyD,CACpH,KAAM,CAAE,eAAAC,EAAgB,aAAAC,EAAc,SAAAC,EAAU,eAAAC,EAAgB,YAAAC,EAAa,aAAAC,EAAc,QAAAC,EAAS,MAAAC,EAAO,SAAAC,CAAa,EAAA,eAAgBT,EACpIU,EAAuBV,EAASD,CAAI,EACpCY,EAAyBX,EAASD,CAAI,EAEnC,MAAA,CACL,SAAAU,EACA,MAAAD,EACA,QAAAD,EACA,KAAMF,EACN,SAAAF,EACA,eAAgB,CACd,IAAKG,EACL,SAAU,IAAM,CACCF,GACjB,EACA,MAAOH,CACT,EACA,aAAAC,CAAA,CAEJ,CAsBA,SAASU,EAA2Bb,EAAiD,CAC7E,MAAAO,EAAeO,MAAwB,IAAI,EAC3CC,EAAOC,iBAAeT,CAAY,EAElCD,EAA4CQ,MAAI,CAAA,CAAE,EAClDG,EAASC,aAAWlB,CAAI,EAI9B,MAAO,CAAE,MAF+Bc,EAAAA,IAAI,CAAE,MAAO,EAAG,IAAK,GAAI,QAAS,EAAG,MAAO,CAAG,CAAA,EAEvE,OAAAG,EAAQ,YAAAX,EAAa,KAAAS,EAAM,aAAAR,CAAa,CAC1D,CAEA,SAASY,EAAyBV,EAA4CQ,EAA8CG,EAAkC,CAC5J,OAAQC,GAA0B,CAChC,KAAM,CAAE,MAAAC,EAAQ,EAAG,MAAAC,EAAQ,GAAMd,EAAM,MACvC,GAAI,OAAOW,GAAa,SACtB,OAAO,KAAK,KAAKC,GAAiBD,EAAWG,EAAM,EAErD,IAAIC,EAAM,EACNC,EAAW,EACf,QAASC,EAAIJ,EAAOI,EAAIT,EAAO,MAAM,OAAQS,IAAK,CAC1C,MAAAX,EAAOK,EAASM,CAAC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AW,0BAA0BnD,EAAM,MAAM,KAAK,IACtD,gBAAiB,QACnB,CAAA,EAEH,EAEM,MAAA,CACL,SAAAC,EACA,MAAAD,EACA,QAAAD,EACA,eAAAH,EACA,SAAAD,EACA,eAAAF,EACA,aAAAC,EACA,YAAAG,EACA,aAAAC,CAAA,CAEJ"}
@@ -1 +1 @@
1
- @font-face{font-family:iconfont;src:url(fonts/iconfont.woff2?t=39586) format("woff2"),url(fonts/iconfont.woff?t=86572) format("woff"),url(fonts/iconfont.ttf?t=70413) format("truetype")}.king-icon{font-family:iconfont!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-king-title-icon:before{content:"\e680"}
1
+ @font-face{font-family:iconfont;src:url(fonts/iconfont.woff2?t=55426) format("woff2"),url(fonts/iconfont.woff?t=98639) format("woff"),url(fonts/iconfont.ttf?t=74018) format("truetype")}.king-icon{font-family:iconfont!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-king-title-icon:before{content:"\e680"}
@@ -1 +1 @@
1
- :root{--king-color-white:#ffffff;--king-color-primary:#409eff;--king-color-success:#67c23a;--king-color-warning:#e6a23c;--king-color-danger:#f56c6c;--king-color-error:#f56c6c;--king-color-info:#909399;--king-transition-duration:0.3s}.king-button--primary{--king-button-text-color:var(--king-color-primary)}.king-button--success{--king-button-text-color:var(--king-color-success)}.king-button--warning{--king-button-text-color:var(--king-color-warning)}.king-button--danger{--king-button-text-color:var(--king-color-danger)}.king-button--error{--king-button-text-color:var(--king-color-error)}.king-button--info{--king-button-text-color:var(--king-color-info)}.king-button{color:var(--king-button-text-color)}.king-scrollbar{overflow:hidden;position:relative;z-index:auto;height:100%;width:100%}.king-scrollbar .king-scrollbar-container{width:100%;overflow:scroll;height:100%;min-height:inherit;max-height:inherit;scrollbar-width:none}.king-scrollbar .king-scrollbar-content{width:-moz-fit-content;width:fit-content}.king-scrollbar .king-scrollbar-rail{position:absolute}.king-scrollbar .king-scrollbar-rail--vertical{right:0;width:5px;top:2px;bottom:2px;right:4px}.king-scrollbar .king-scrollbar-rail--horizontal{bottom:2px;height:5px;left:2px;right:2px}.king-scrollbar .king-scrollbar-rail__scrollbar--vertical{background:rgba(0,0,0,.25);position:absolute;border-radius:5px;width:100%;cursor:pointer}.king-scrollbar .king-scrollbar-rail__scrollbar--horizontal{background:rgba(0,0,0,.25);position:absolute;border-radius:5px;height:100%;cursor:pointer}.v-vl-items{width:-moz-fit-content;width:fit-content}.king-scale-virtual-list{width:100%;height:100%}.king-scale-virtual-list .king-scale-virtual-list-container{margin:0 auto;position:relative}.king-scale-virtual-list .king-scale-vittual-wrapper{width:-moz-fit-content;width:fit-content;margin:0 auto;position:absolute;left:50%}.king-pro-title{border-bottom:1px solid #ccc;font-weight:500;display:flex;align-items:center}.king-pro-title .icon{margin-right:10px}.king-pro-title--unborder{border:none}.king-pro-modal .ant-modal-content{padding:0}.king-pro-modal .ant-modal-header{height:56px;padding-left:32px;padding-right:24px;display:flex;justify-content:space-between;align-items:center;background:#f1f7ff;border-bottom:1px solid #e6e8ea}.king-pro-modal .ant-modal-body{padding:10px 20px;max-height:65vh;overflow:auto}.king-pro-modal .ant-modal-footer{height:56px;display:flex;padding:0 16px;justify-content:flex-end;align-items:center;border-top:1px solid #e6e8ea}.king-pro-modal .ant-modal-title{flex:1}.king-pro-modal .pro-modal-title{cursor:move;width:100%}.king-pro-area-select{width:100%}@font-face{font-family:iconfont;src:url(fonts/iconfont.woff2?t=44896) format("woff2"),url(fonts/iconfont.woff?t=84806) format("woff"),url(fonts/iconfont.ttf?t=4660) format("truetype")}.king-icon{font-family:iconfont!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-king-title-icon:before{content:"\e680"}
1
+ :root{--king-color-white:#ffffff;--king-color-primary:#409eff;--king-color-success:#67c23a;--king-color-warning:#e6a23c;--king-color-danger:#f56c6c;--king-color-error:#f56c6c;--king-color-info:#909399;--king-transition-duration:0.3s}.king-button--primary{--king-button-text-color:var(--king-color-primary)}.king-button--success{--king-button-text-color:var(--king-color-success)}.king-button--warning{--king-button-text-color:var(--king-color-warning)}.king-button--danger{--king-button-text-color:var(--king-color-danger)}.king-button--error{--king-button-text-color:var(--king-color-error)}.king-button--info{--king-button-text-color:var(--king-color-info)}.king-button{color:var(--king-button-text-color)}.king-scrollbar{overflow:hidden;position:relative;z-index:auto;height:100%;width:100%}.king-scrollbar .king-scrollbar-container{width:100%;overflow:scroll;height:100%;min-height:inherit;max-height:inherit;scrollbar-width:none}.king-scrollbar .king-scrollbar-content{width:-moz-fit-content;width:fit-content}.king-scrollbar .king-scrollbar-rail{position:absolute}.king-scrollbar .king-scrollbar-rail--vertical{right:0;width:5px;top:2px;bottom:2px;right:4px}.king-scrollbar .king-scrollbar-rail--horizontal{bottom:2px;height:5px;left:2px;right:2px}.king-scrollbar .king-scrollbar-rail__scrollbar--vertical{background:rgba(0,0,0,.25);position:absolute;border-radius:5px;width:100%;cursor:pointer}.king-scrollbar .king-scrollbar-rail__scrollbar--horizontal{background:rgba(0,0,0,.25);position:absolute;border-radius:5px;height:100%;cursor:pointer}.v-vl-items{width:-moz-fit-content;width:fit-content}.king-scale-virtual-list{width:100%;height:100%}.king-scale-virtual-list .king-scale-virtual-list-container{margin:0 auto;position:relative}.king-scale-virtual-list .king-scale-vittual-wrapper{width:-moz-fit-content;width:fit-content;margin:0 auto;position:absolute;left:50%}.king-pro-title{border-bottom:1px solid #ccc;font-weight:500;display:flex;align-items:center}.king-pro-title .icon{margin-right:10px}.king-pro-title--unborder{border:none}.king-pro-modal .ant-modal-content{padding:0}.king-pro-modal .ant-modal-header{height:56px;padding-left:32px;padding-right:24px;display:flex;justify-content:space-between;align-items:center;background:#f1f7ff;border-bottom:1px solid #e6e8ea}.king-pro-modal .ant-modal-body{padding:10px 20px;max-height:65vh;overflow:auto}.king-pro-modal .ant-modal-footer{height:56px;display:flex;padding:0 16px;justify-content:flex-end;align-items:center;border-top:1px solid #e6e8ea}.king-pro-modal .ant-modal-title{flex:1}.king-pro-modal .pro-modal-title{cursor:move;width:100%}.king-pro-area-select{width:100%}@font-face{font-family:iconfont;src:url(fonts/iconfont.woff2?t=96225) format("woff2"),url(fonts/iconfont.woff?t=75235) format("woff"),url(fonts/iconfont.ttf?t=64667) format("truetype")}.king-icon{font-family:iconfont!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-king-title-icon:before{content:"\e680"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@king-one/antdv",
3
3
  "type": "module",
4
- "version": "1.0.72",
4
+ "version": "1.0.73",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",