stk-table-vue 0.8.14 → 0.9.0-beta.1

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 (38) hide show
  1. package/README.md +172 -172
  2. package/lib/src/StkTable/StkTable.vue.d.ts +19 -1
  3. package/lib/src/StkTable/useScrollbar.d.ts +57 -0
  4. package/lib/src/StkTable/utils/index.d.ts +7 -0
  5. package/lib/stk-table-vue.js +396 -205
  6. package/lib/style.css +42 -1
  7. package/package.json +74 -74
  8. package/src/StkTable/StkTable.vue +1730 -1665
  9. package/src/StkTable/components/DragHandle.vue +9 -9
  10. package/src/StkTable/components/SortIcon.vue +6 -6
  11. package/src/StkTable/components/TriangleIcon.vue +3 -3
  12. package/src/StkTable/const.ts +50 -50
  13. package/src/StkTable/index.ts +4 -4
  14. package/src/StkTable/style.less +627 -578
  15. package/src/StkTable/types/highlightDimOptions.ts +26 -26
  16. package/src/StkTable/types/index.ts +297 -297
  17. package/src/StkTable/useAutoResize.ts +91 -91
  18. package/src/StkTable/useColResize.ts +216 -216
  19. package/src/StkTable/useFixedCol.ts +150 -150
  20. package/src/StkTable/useFixedStyle.ts +75 -75
  21. package/src/StkTable/useGetFixedColPosition.ts +65 -65
  22. package/src/StkTable/useHighlight.ts +257 -257
  23. package/src/StkTable/useKeyboardArrowScroll.ts +112 -112
  24. package/src/StkTable/useMaxRowSpan.ts +55 -55
  25. package/src/StkTable/useMergeCells.ts +120 -120
  26. package/src/StkTable/useRowExpand.ts +88 -88
  27. package/src/StkTable/useScrollRowByRow.ts +113 -113
  28. package/src/StkTable/useScrollbar.ts +187 -0
  29. package/src/StkTable/useThDrag.ts +102 -102
  30. package/src/StkTable/useTrDrag.ts +113 -113
  31. package/src/StkTable/useTree.ts +161 -161
  32. package/src/StkTable/useVirtualScroll.ts +494 -494
  33. package/src/StkTable/utils/constRefUtils.ts +29 -29
  34. package/src/StkTable/utils/index.ts +287 -258
  35. package/src/StkTable/utils/useTriggerRef.ts +33 -33
  36. package/src/VirtualTree.vue +622 -622
  37. package/src/VirtualTreeSelect.vue +367 -367
  38. package/src/vite-env.d.ts +10 -10
@@ -1,257 +1,257 @@
1
- import { Ref, computed } from 'vue';
2
- import { HIGHLIGHT_CELL_CLASS, HIGHLIGHT_COLOR, HIGHLIGHT_DURATION, HIGHLIGHT_ROW_CLASS } from './const';
3
- import { HighlightConfig, UniqKey } from './types';
4
- import { HighlightDimCellOption, HighlightDimRowOption } from './types/highlightDimOptions';
5
- import { pureCellKeyGen } from './utils';
6
-
7
- type Params = {
8
- props: any;
9
- stkTableId: string;
10
- tableContainerRef: Ref<HTMLDivElement | undefined>;
11
- };
12
- /** 存放高亮行信息 */
13
- type HighlightDimRowStore = {
14
- /** 动画开始时间戳 */
15
- readonly ts: number;
16
- /** 行是否可见 */
17
- visible: boolean;
18
- /** 动画关键帧 */
19
- keyframe: Parameters<Animatable['animate']>['0'];
20
- /** 动画初始持续时间 */
21
- readonly duration: number;
22
- };
23
-
24
- /**
25
- * 高亮单元格,行
26
- */
27
- export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
28
- const config: HighlightConfig = props.highlightConfig;
29
-
30
- /** 高亮颜色 */
31
- const highlightColor = {
32
- light: HIGHLIGHT_COLOR.light,
33
- dark: HIGHLIGHT_COLOR.dark,
34
- };
35
- /** 持续时间 */
36
- const highlightDuration = computed(() => (config.duration ? config.duration * 1000 : HIGHLIGHT_DURATION));
37
- /** 高亮频率*/
38
- const highlightFrequency = computed(() => (config.fps && config.fps > 0 ? 1000 / config.fps : null));
39
- /** 高亮帧数(非帧率),用于 timing-function: steps() */
40
- const highlightSteps = computed(() => (highlightFrequency.value ? Math.round(highlightDuration.value / highlightFrequency.value) : null));
41
- /** 高亮开始 */
42
- const highlightFrom = computed(() => highlightColor[props.theme as 'light' | 'dark'].from);
43
-
44
- /**
45
- * 存放高亮行的状态-使用animation api实现
46
- * @key 行唯一键
47
- * @value 记录高亮配置
48
- */
49
- const highlightDimRowsAnimation = new Map<UniqKey, HighlightDimRowStore>();
50
- /** 是否正在计算高亮行的循环-使用animation api实现 */
51
- let calcHighlightDimLoopAnimation = false;
52
-
53
- /** 高亮后渐暗的行定时器 */
54
- const highlightDimRowsTimeout = new Map();
55
- /** 高亮后渐暗的单元格定时器 */
56
- const highlightDimCellsTimeout = new Map();
57
-
58
- /** 高亮函数的默认参数 */
59
- const defaultHighlightDimOption = computed(() => {
60
- const keyframe: PropertyIndexedKeyframes = { backgroundColor: [highlightFrom.value, ''] };
61
- if (highlightSteps.value) {
62
- keyframe.easing = `steps(${highlightSteps.value})`;
63
- }
64
- return { duration: highlightDuration.value, keyframe };
65
- });
66
-
67
- /**
68
- * 计算高亮渐暗颜色的循环
69
- */
70
- function calcRowHighlightLoop() {
71
- if (calcHighlightDimLoopAnimation) return;
72
- calcHighlightDimLoopAnimation = true;
73
- const recursion = () => {
74
- window.requestAnimationFrame(
75
- () => {
76
- const nowTs = performance.now();
77
- highlightDimRowsAnimation.forEach((store, rowKeyValue) => {
78
- const { ts, duration } = store;
79
- const timeOffset = nowTs - ts;
80
- if (nowTs - ts < duration) {
81
- updateRowAnimation(rowKeyValue, store, timeOffset);
82
- } else {
83
- highlightDimRowsAnimation.delete(rowKeyValue);
84
- }
85
- });
86
-
87
- if (highlightDimRowsAnimation.size > 0) {
88
- // 还有高亮的行,则下一次循环
89
- recursion();
90
- } else {
91
- // 没有则停止循环
92
- calcHighlightDimLoopAnimation = false;
93
- highlightDimRowsAnimation.clear();
94
- }
95
- } /* , highlightFrequency */,
96
- );
97
- };
98
- recursion();
99
- }
100
-
101
- /**
102
- * 高亮一个单元格。暂不支持虚拟滚动高亮状态记忆。
103
- * @param rowKeyValue 一行的key
104
- * @param colKeyValue 列key
105
- * @param options.method css-使用css渲染,animation-使用animation api。默认animation;
106
- * @param option.className 自定义css动画的class。
107
- * @param option.keyframe 如果自定义keyframe,则 highlightConfig.fps 将会失效。Keyframe:https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
108
- * @param option.duration 动画时长。method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。
109
- */
110
- function setHighlightDimCell(rowKeyValue: UniqKey, colKeyValue: string, option: HighlightDimCellOption = {}) {
111
- const cellEl = tableContainerRef.value?.querySelector<HTMLElement>(`[data-row-key="${rowKeyValue}"] [data-col-key="${colKeyValue}"]`);
112
- if (!cellEl) return;
113
- const { className, method, duration, keyframe } = {
114
- className: HIGHLIGHT_CELL_CLASS,
115
- method: 'animation',
116
- ...defaultHighlightDimOption.value,
117
- ...option,
118
- };
119
- if (method === 'animation') {
120
- cellEl.animate(keyframe, duration);
121
- } else {
122
- highlightCellsInCssKeyFrame(cellEl, rowKeyValue, className, duration);
123
- }
124
- }
125
-
126
- /**
127
- * 高亮一行
128
- * @param rowKeyValues 行唯一键的数组
129
- * @param option.method css-使用css渲染,animation-使用animation api,js-使用js计算颜色。默认animation
130
- * @param option.className 自定义css动画的class。
131
- * @param option.keyframe 如果自定义keyframe,则 highlightConfig.fps 将会失效。Keyframe:https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats。
132
- * @param option.duration 动画时长。method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。。
133
- */
134
- function setHighlightDimRow(rowKeyValues: UniqKey[], option: HighlightDimRowOption = {}) {
135
- if (!Array.isArray(rowKeyValues)) rowKeyValues = [rowKeyValues];
136
- if (!rowKeyValues.length) return;
137
- const { className, method, keyframe, duration } = {
138
- className: HIGHLIGHT_ROW_CLASS,
139
- method: 'animation',
140
- ...defaultHighlightDimOption.value,
141
- ...option,
142
- };
143
-
144
- if (method === 'animation') {
145
- if (props.virtual) {
146
- // -------- 用animation 接口实现动画
147
- const nowTs = performance.now();
148
- for (let i = 0; i < rowKeyValues.length; i++) {
149
- const rowKeyValue = rowKeyValues[i];
150
- const store: HighlightDimRowStore = { ts: nowTs, visible: false, keyframe, duration };
151
- highlightDimRowsAnimation.set(rowKeyValue, store);
152
- updateRowAnimation(rowKeyValue, store, 0);
153
- }
154
- calcRowHighlightLoop();
155
- } else {
156
- // -------- use Element.animate
157
- for (let i = 0; i < rowKeyValues.length; i++) {
158
- const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValues[i])) as HTMLTableRowElement | null;
159
- if (!rowEl) continue;
160
- rowEl.animate(keyframe, duration);
161
- }
162
- }
163
- } else {
164
- // -------- use css keyframe
165
- highlightRowsInCssKeyframe(rowKeyValues, className, duration);
166
- }
167
- }
168
-
169
- /**
170
- * 使用css @keyframes动画,实现高亮行动画
171
- * 此方案作为兼容方式。v0.3.4 将使用Element.animate 接口实现动画。
172
- */
173
- function highlightRowsInCssKeyframe(rowKeyValues: UniqKey[], className: string, duration: number) {
174
- /**是否需要重绘 */
175
- let needRepaint = false;
176
- const rowElTemp: HTMLTableRowElement[] = [];
177
- for (let i = 0; i < rowKeyValues.length; i++) {
178
- const rowKeyValue = rowKeyValues[i];
179
- const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValue)) as HTMLTableRowElement | null;
180
- if (!rowEl) continue;
181
- if (rowEl.classList.contains(className)) {
182
- rowEl.classList.remove(className);
183
- needRepaint = true;
184
- }
185
- rowElTemp.push(rowEl);
186
- // 动画结束移除class
187
- window.clearTimeout(highlightDimRowsTimeout.get(rowKeyValue));
188
- highlightDimRowsTimeout.set(
189
- rowKeyValue,
190
- window.setTimeout(() => {
191
- rowEl.classList.remove(className);
192
- highlightDimRowsTimeout.delete(rowKeyValue); // 回收内存
193
- }, duration),
194
- );
195
- }
196
- if (needRepaint) {
197
- void tableContainerRef.value?.offsetWidth; //强制浏览器重绘
198
- }
199
- rowElTemp.forEach(el => el.classList.add(className)); // 统一添加动画
200
- }
201
-
202
- /**
203
- * 使用css @keyframes动画,实现高亮单元格动画
204
- * 此方案作为兼容方式。v0.3.4 将使用Element.animate 接口实现动画。
205
- */
206
- function highlightCellsInCssKeyFrame(cellEl: HTMLElement, rowKeyValue: UniqKey, className: string, duration: number) {
207
- if (cellEl.classList.contains(className)) {
208
- cellEl.classList.remove(className);
209
- void cellEl.offsetHeight; // 通知浏览器重绘
210
- }
211
- cellEl.classList.add(className);
212
- window.clearTimeout(highlightDimCellsTimeout.get(rowKeyValue));
213
- highlightDimCellsTimeout.set(
214
- rowKeyValue,
215
- window.setTimeout(() => {
216
- cellEl.classList.remove(className);
217
- highlightDimCellsTimeout.delete(rowKeyValue);
218
- }, duration),
219
- );
220
- }
221
-
222
- /**
223
- * 更新行状态
224
- * @param rowKeyValue 行唯一键
225
- * @param store highlightDimRowStore 的引用对象
226
- * @param timeOffset 距动画开始经过的时长
227
- */
228
- function updateRowAnimation(rowKeyValue: UniqKey, store: HighlightDimRowStore, timeOffset: number) {
229
- const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValue));
230
- const { visible, keyframe, duration: initialDuration } = store;
231
- if (!rowEl) {
232
- if (visible) {
233
- store.visible = false; // 标记为不可见
234
- }
235
- return;
236
- }
237
- // 只有元素 不可见 -> 可见 时才需要更新
238
- if (!visible) {
239
- store.visible = true; // 标记为可见
240
- /** 经过的时间 ÷ 高亮持续时间 计算出 颜色过渡进度 (0-1) */
241
- const iterationStart = timeOffset / initialDuration;
242
- rowEl.animate(keyframe, {
243
- duration: initialDuration - timeOffset,
244
- /** 从什么时候开始,0-1 */
245
- iterationStart,
246
- /** 持续多久 0-1 */
247
- iterations: 1 - iterationStart,
248
- });
249
- }
250
- }
251
-
252
- return {
253
- highlightSteps,
254
- setHighlightDimRow,
255
- setHighlightDimCell,
256
- };
257
- }
1
+ import { Ref, computed } from 'vue';
2
+ import { HIGHLIGHT_CELL_CLASS, HIGHLIGHT_COLOR, HIGHLIGHT_DURATION, HIGHLIGHT_ROW_CLASS } from './const';
3
+ import { HighlightConfig, UniqKey } from './types';
4
+ import { HighlightDimCellOption, HighlightDimRowOption } from './types/highlightDimOptions';
5
+ import { pureCellKeyGen } from './utils';
6
+
7
+ type Params = {
8
+ props: any;
9
+ stkTableId: string;
10
+ tableContainerRef: Ref<HTMLDivElement | undefined>;
11
+ };
12
+ /** 存放高亮行信息 */
13
+ type HighlightDimRowStore = {
14
+ /** 动画开始时间戳 */
15
+ readonly ts: number;
16
+ /** 行是否可见 */
17
+ visible: boolean;
18
+ /** 动画关键帧 */
19
+ keyframe: Parameters<Animatable['animate']>['0'];
20
+ /** 动画初始持续时间 */
21
+ readonly duration: number;
22
+ };
23
+
24
+ /**
25
+ * 高亮单元格,行
26
+ */
27
+ export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
28
+ const config: HighlightConfig = props.highlightConfig;
29
+
30
+ /** 高亮颜色 */
31
+ const highlightColor = {
32
+ light: HIGHLIGHT_COLOR.light,
33
+ dark: HIGHLIGHT_COLOR.dark,
34
+ };
35
+ /** 持续时间 */
36
+ const highlightDuration = computed(() => (config.duration ? config.duration * 1000 : HIGHLIGHT_DURATION));
37
+ /** 高亮频率*/
38
+ const highlightFrequency = computed(() => (config.fps && config.fps > 0 ? 1000 / config.fps : null));
39
+ /** 高亮帧数(非帧率),用于 timing-function: steps() */
40
+ const highlightSteps = computed(() => (highlightFrequency.value ? Math.round(highlightDuration.value / highlightFrequency.value) : null));
41
+ /** 高亮开始 */
42
+ const highlightFrom = computed(() => highlightColor[props.theme as 'light' | 'dark'].from);
43
+
44
+ /**
45
+ * 存放高亮行的状态-使用animation api实现
46
+ * @key 行唯一键
47
+ * @value 记录高亮配置
48
+ */
49
+ const highlightDimRowsAnimation = new Map<UniqKey, HighlightDimRowStore>();
50
+ /** 是否正在计算高亮行的循环-使用animation api实现 */
51
+ let calcHighlightDimLoopAnimation = false;
52
+
53
+ /** 高亮后渐暗的行定时器 */
54
+ const highlightDimRowsTimeout = new Map();
55
+ /** 高亮后渐暗的单元格定时器 */
56
+ const highlightDimCellsTimeout = new Map();
57
+
58
+ /** 高亮函数的默认参数 */
59
+ const defaultHighlightDimOption = computed(() => {
60
+ const keyframe: PropertyIndexedKeyframes = { backgroundColor: [highlightFrom.value, ''] };
61
+ if (highlightSteps.value) {
62
+ keyframe.easing = `steps(${highlightSteps.value})`;
63
+ }
64
+ return { duration: highlightDuration.value, keyframe };
65
+ });
66
+
67
+ /**
68
+ * 计算高亮渐暗颜色的循环
69
+ */
70
+ function calcRowHighlightLoop() {
71
+ if (calcHighlightDimLoopAnimation) return;
72
+ calcHighlightDimLoopAnimation = true;
73
+ const recursion = () => {
74
+ window.requestAnimationFrame(
75
+ () => {
76
+ const nowTs = performance.now();
77
+ highlightDimRowsAnimation.forEach((store, rowKeyValue) => {
78
+ const { ts, duration } = store;
79
+ const timeOffset = nowTs - ts;
80
+ if (nowTs - ts < duration) {
81
+ updateRowAnimation(rowKeyValue, store, timeOffset);
82
+ } else {
83
+ highlightDimRowsAnimation.delete(rowKeyValue);
84
+ }
85
+ });
86
+
87
+ if (highlightDimRowsAnimation.size > 0) {
88
+ // 还有高亮的行,则下一次循环
89
+ recursion();
90
+ } else {
91
+ // 没有则停止循环
92
+ calcHighlightDimLoopAnimation = false;
93
+ highlightDimRowsAnimation.clear();
94
+ }
95
+ } /* , highlightFrequency */,
96
+ );
97
+ };
98
+ recursion();
99
+ }
100
+
101
+ /**
102
+ * 高亮一个单元格。暂不支持虚拟滚动高亮状态记忆。
103
+ * @param rowKeyValue 一行的key
104
+ * @param colKeyValue 列key
105
+ * @param options.method css-使用css渲染,animation-使用animation api。默认animation;
106
+ * @param option.className 自定义css动画的class。
107
+ * @param option.keyframe 如果自定义keyframe,则 highlightConfig.fps 将会失效。Keyframe:https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
108
+ * @param option.duration 动画时长。method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。
109
+ */
110
+ function setHighlightDimCell(rowKeyValue: UniqKey, colKeyValue: string, option: HighlightDimCellOption = {}) {
111
+ const cellEl = tableContainerRef.value?.querySelector<HTMLElement>(`[data-row-key="${rowKeyValue}"] [data-col-key="${colKeyValue}"]`);
112
+ if (!cellEl) return;
113
+ const { className, method, duration, keyframe } = {
114
+ className: HIGHLIGHT_CELL_CLASS,
115
+ method: 'animation',
116
+ ...defaultHighlightDimOption.value,
117
+ ...option,
118
+ };
119
+ if (method === 'animation') {
120
+ cellEl.animate(keyframe, duration);
121
+ } else {
122
+ highlightCellsInCssKeyFrame(cellEl, rowKeyValue, className, duration);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * 高亮一行
128
+ * @param rowKeyValues 行唯一键的数组
129
+ * @param option.method css-使用css渲染,animation-使用animation api,js-使用js计算颜色。默认animation
130
+ * @param option.className 自定义css动画的class。
131
+ * @param option.keyframe 如果自定义keyframe,则 highlightConfig.fps 将会失效。Keyframe:https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats。
132
+ * @param option.duration 动画时长。method='css'状态下,用于移除class,如果传入了className则需要与自定义的动画时间一致。。
133
+ */
134
+ function setHighlightDimRow(rowKeyValues: UniqKey[], option: HighlightDimRowOption = {}) {
135
+ if (!Array.isArray(rowKeyValues)) rowKeyValues = [rowKeyValues];
136
+ if (!rowKeyValues.length) return;
137
+ const { className, method, keyframe, duration } = {
138
+ className: HIGHLIGHT_ROW_CLASS,
139
+ method: 'animation',
140
+ ...defaultHighlightDimOption.value,
141
+ ...option,
142
+ };
143
+
144
+ if (method === 'animation') {
145
+ if (props.virtual) {
146
+ // -------- 用animation 接口实现动画
147
+ const nowTs = performance.now();
148
+ for (let i = 0; i < rowKeyValues.length; i++) {
149
+ const rowKeyValue = rowKeyValues[i];
150
+ const store: HighlightDimRowStore = { ts: nowTs, visible: false, keyframe, duration };
151
+ highlightDimRowsAnimation.set(rowKeyValue, store);
152
+ updateRowAnimation(rowKeyValue, store, 0);
153
+ }
154
+ calcRowHighlightLoop();
155
+ } else {
156
+ // -------- use Element.animate
157
+ for (let i = 0; i < rowKeyValues.length; i++) {
158
+ const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValues[i])) as HTMLTableRowElement | null;
159
+ if (!rowEl) continue;
160
+ rowEl.animate(keyframe, duration);
161
+ }
162
+ }
163
+ } else {
164
+ // -------- use css keyframe
165
+ highlightRowsInCssKeyframe(rowKeyValues, className, duration);
166
+ }
167
+ }
168
+
169
+ /**
170
+ * 使用css @keyframes动画,实现高亮行动画
171
+ * 此方案作为兼容方式。v0.3.4 将使用Element.animate 接口实现动画。
172
+ */
173
+ function highlightRowsInCssKeyframe(rowKeyValues: UniqKey[], className: string, duration: number) {
174
+ /**是否需要重绘 */
175
+ let needRepaint = false;
176
+ const rowElTemp: HTMLTableRowElement[] = [];
177
+ for (let i = 0; i < rowKeyValues.length; i++) {
178
+ const rowKeyValue = rowKeyValues[i];
179
+ const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValue)) as HTMLTableRowElement | null;
180
+ if (!rowEl) continue;
181
+ if (rowEl.classList.contains(className)) {
182
+ rowEl.classList.remove(className);
183
+ needRepaint = true;
184
+ }
185
+ rowElTemp.push(rowEl);
186
+ // 动画结束移除class
187
+ window.clearTimeout(highlightDimRowsTimeout.get(rowKeyValue));
188
+ highlightDimRowsTimeout.set(
189
+ rowKeyValue,
190
+ window.setTimeout(() => {
191
+ rowEl.classList.remove(className);
192
+ highlightDimRowsTimeout.delete(rowKeyValue); // 回收内存
193
+ }, duration),
194
+ );
195
+ }
196
+ if (needRepaint) {
197
+ void tableContainerRef.value?.offsetWidth; //强制浏览器重绘
198
+ }
199
+ rowElTemp.forEach(el => el.classList.add(className)); // 统一添加动画
200
+ }
201
+
202
+ /**
203
+ * 使用css @keyframes动画,实现高亮单元格动画
204
+ * 此方案作为兼容方式。v0.3.4 将使用Element.animate 接口实现动画。
205
+ */
206
+ function highlightCellsInCssKeyFrame(cellEl: HTMLElement, rowKeyValue: UniqKey, className: string, duration: number) {
207
+ if (cellEl.classList.contains(className)) {
208
+ cellEl.classList.remove(className);
209
+ void cellEl.offsetHeight; // 通知浏览器重绘
210
+ }
211
+ cellEl.classList.add(className);
212
+ window.clearTimeout(highlightDimCellsTimeout.get(rowKeyValue));
213
+ highlightDimCellsTimeout.set(
214
+ rowKeyValue,
215
+ window.setTimeout(() => {
216
+ cellEl.classList.remove(className);
217
+ highlightDimCellsTimeout.delete(rowKeyValue);
218
+ }, duration),
219
+ );
220
+ }
221
+
222
+ /**
223
+ * 更新行状态
224
+ * @param rowKeyValue 行唯一键
225
+ * @param store highlightDimRowStore 的引用对象
226
+ * @param timeOffset 距动画开始经过的时长
227
+ */
228
+ function updateRowAnimation(rowKeyValue: UniqKey, store: HighlightDimRowStore, timeOffset: number) {
229
+ const rowEl = document.getElementById(stkTableId + '-' + String(rowKeyValue));
230
+ const { visible, keyframe, duration: initialDuration } = store;
231
+ if (!rowEl) {
232
+ if (visible) {
233
+ store.visible = false; // 标记为不可见
234
+ }
235
+ return;
236
+ }
237
+ // 只有元素 不可见 -> 可见 时才需要更新
238
+ if (!visible) {
239
+ store.visible = true; // 标记为可见
240
+ /** 经过的时间 ÷ 高亮持续时间 计算出 颜色过渡进度 (0-1) */
241
+ const iterationStart = timeOffset / initialDuration;
242
+ rowEl.animate(keyframe, {
243
+ duration: initialDuration - timeOffset,
244
+ /** 从什么时候开始,0-1 */
245
+ iterationStart,
246
+ /** 持续多久 0-1 */
247
+ iterations: 1 - iterationStart,
248
+ });
249
+ }
250
+ }
251
+
252
+ return {
253
+ highlightSteps,
254
+ setHighlightDimRow,
255
+ setHighlightDimCell,
256
+ };
257
+ }