@shijiu/jsview-vue 2.2.128 → 2.2.201

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 (91) hide show
  1. package/bin/browser/BrowserApic.vue.mjs +2 -2
  2. package/bin/browser/BrowserApic2.vue.mjs +2 -2
  3. package/bin/browser/BrowserApicLib.mjs +8 -2
  4. package/bin/browser/BrowserJsvFragShaderView.vue.mjs +63 -0
  5. package/bin/jsview-vue.mjs +1604 -423
  6. package/bin/types/JsViewEngineWidget/JsvFocus/JsvFocusManager.d.ts +8 -6
  7. package/bin/types/JsViewEngineWidget/MetroWidget/Dispatcher.d.ts +10 -12
  8. package/bin/types/JsViewEngineWidget/MetroWidget/ListWidget.vue.d.ts +3 -3
  9. package/bin/types/JsViewEngineWidget/MetroWidget/MetroWidget.vue.d.ts +3 -3
  10. package/bin/types/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.d.ts +2 -2
  11. package/bin/types/JsViewEngineWidget/MetroWidget/RenderItem.d.ts +3 -0
  12. package/bin/types/JsViewEngineWidget/TemplateParser/ListMetroTemplate.d.ts +1 -0
  13. package/bin/types/JsViewEngineWidget/TemplateParser/TemplateItemAdder.d.ts +1 -1
  14. package/bin/types/JsViewEngineWidget/index.d.ts +10 -1
  15. package/bin/types/JsViewVueTools/ConstSymbol.d.ts +2 -2
  16. package/bin/types/JsViewVueTools/JsvFederationTools.d.ts +16 -0
  17. package/bin/types/JsViewVueTools/JsvPerformance.d.ts +5 -0
  18. package/bin/types/JsViewVueTools/JsvPreDownloader.d.ts +33 -0
  19. package/bin/types/JsViewVueTools/JsvTextureStore/JsvTextureStore.d.ts +45 -1
  20. package/bin/types/JsViewVueTools/index.d.ts +19 -11
  21. package/bin/types/JsViewVueWidget/JsvApic/JsvApic/BrowserApic.vue.d.ts +1 -1
  22. package/bin/types/JsViewVueWidget/JsvApic/JsvApic/JsvApic.vue.d.ts +1 -1
  23. package/bin/types/JsViewVueWidget/JsvApic/JsvApic2/BrowserApic2.vue.d.ts +1 -1
  24. package/bin/types/JsViewVueWidget/JsvApic/JsvApic2/JsvApic2.vue.d.ts +1 -1
  25. package/bin/types/JsViewVueWidget/JsvApic/JsvBrowserApicLib/Viewer.d.ts +2 -1
  26. package/bin/types/JsViewVueWidget/JsvClipDiv/JsvClipDiv.vue.d.ts +70 -0
  27. package/bin/types/JsViewVueWidget/JsvClipDiv/index.d.ts +1 -0
  28. package/bin/types/JsViewVueWidget/JsvDriftScope/JsvDriftScope.vue.d.ts +104 -0
  29. package/bin/types/JsViewVueWidget/JsvDriftScope/index.d.ts +1 -0
  30. package/bin/types/JsViewVueWidget/JsvFragShaderView/BrowserJsvFragShaderView.vue.d.ts +13 -0
  31. package/bin/types/JsViewVueWidget/JsvFragShaderView/JsvFragShaderView.vue.d.ts +13 -0
  32. package/bin/types/JsViewVueWidget/JsvFragShaderView/index.d.ts +2 -0
  33. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/ActorControl.d.ts +43 -17
  34. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/SetAction.d.ts +5 -5
  35. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/SetCondition.d.ts +4 -2
  36. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/SetState.d.ts +7 -7
  37. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/SyncLinkManager.d.ts +18 -0
  38. package/bin/types/JsViewVueWidget/JsvFreeMoveActor/index.d.ts +2 -0
  39. package/bin/types/JsViewVueWidget/JsvNinePatch.vue.d.ts +1 -0
  40. package/bin/types/JsViewVueWidget/JsvScrollBox/JsvScrollBox.vue.d.ts +61 -1
  41. package/bin/types/JsViewVueWidget/JsvScrollBox/JsvScrollFollow.vue.d.ts +153 -0
  42. package/bin/types/JsViewVueWidget/JsvScrollBox/ScrollInnerSymbol.d.ts +4 -0
  43. package/bin/types/JsViewVueWidget/JsvScrollBox/ScrollSymbol.d.ts +9 -4
  44. package/bin/types/JsViewVueWidget/JsvScrollBox/index.d.ts +2 -0
  45. package/bin/types/JsViewVueWidget/index.d.ts +3 -0
  46. package/package.json +1 -1
  47. package/tools/config/rollup.config.mjs +1 -0
  48. package/utils/JsViewEngineWidget/JsvFocus/{JsvFocusManager.js → JsvFocusManager.ts} +12 -12
  49. package/utils/JsViewEngineWidget/MetroWidget/Dispatcher.ts +20 -0
  50. package/utils/JsViewEngineWidget/MetroWidget/ListWidget.vue +27 -10
  51. package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +42 -10
  52. package/utils/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.js +320 -203
  53. package/utils/JsViewEngineWidget/MetroWidget/RenderItem.ts +11 -0
  54. package/utils/JsViewEngineWidget/MetroWidget/TaskManager.ts +8 -0
  55. package/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.ts +20 -10
  56. package/utils/JsViewEngineWidget/TemplateParser/ListMetroTemplate.ts +18 -0
  57. package/utils/JsViewEngineWidget/TemplateParser/TemplateItemAdder.ts +7 -0
  58. package/utils/JsViewEngineWidget/{index.js → index.ts} +1 -1
  59. package/utils/JsViewPlugin/JsvAudio/AudioProxy.js +21 -2
  60. package/utils/JsViewVueTools/ConstSymbol.ts +2 -2
  61. package/utils/JsViewVueTools/JsvPreDownloader.ts +3 -3
  62. package/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.ts +1 -1
  63. package/utils/JsViewVueTools/index.js +19 -19
  64. package/utils/JsViewVueWidget/JsvApic/JsvApic/BrowserApic.vue +2 -2
  65. package/utils/JsViewVueWidget/JsvApic/JsvApic/JsvApic.vue +3 -3
  66. package/utils/JsViewVueWidget/JsvApic/JsvApic2/BrowserApic2.vue +2 -2
  67. package/utils/JsViewVueWidget/JsvApic/JsvApic2/JsvApic2.vue +3 -3
  68. package/utils/JsViewVueWidget/JsvApic/JsvBrowserApicLib/Viewer.js +8 -3
  69. package/utils/JsViewVueWidget/JsvClipDiv/JsvClipDiv.vue +42 -0
  70. package/utils/JsViewVueWidget/JsvClipDiv/index.ts +1 -0
  71. package/utils/JsViewVueWidget/JsvConnectLine/JsvConnectLine.vue +5 -1
  72. package/utils/JsViewVueWidget/JsvDriftScope/JsvDriftScope.vue +82 -0
  73. package/utils/JsViewVueWidget/JsvDriftScope/index.ts +1 -0
  74. package/utils/JsViewVueWidget/JsvFragShaderView/BrowserJsvFragShaderView.vue +48 -0
  75. package/utils/JsViewVueWidget/JsvFragShaderView/JsvFragShaderView.vue +145 -0
  76. package/utils/JsViewVueWidget/JsvFragShaderView/index.js +18 -0
  77. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.ts +142 -63
  78. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.ts +15 -6
  79. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.ts +19 -7
  80. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.ts +15 -11
  81. package/utils/JsViewVueWidget/JsvFreeMoveActor/SyncLinkManager.ts +120 -0
  82. package/utils/JsViewVueWidget/JsvFreeMoveActor/index.js +5 -1
  83. package/utils/JsViewVueWidget/JsvNinePatch.vue +13 -1
  84. package/utils/JsViewVueWidget/JsvScrollBox/JsvScrollBox.vue +257 -48
  85. package/utils/JsViewVueWidget/JsvScrollBox/JsvScrollFollow.vue +468 -0
  86. package/utils/JsViewVueWidget/JsvScrollBox/ScrollInnerSymbol.ts +9 -0
  87. package/utils/JsViewVueWidget/JsvScrollBox/ScrollSymbol.ts +13 -4
  88. package/utils/JsViewVueWidget/JsvScrollBox/index.ts +3 -0
  89. package/utils/JsViewVueWidget/index.js +3 -0
  90. package/utils/JsViewEngineWidget/MetroWidget/Dispatcher.js +0 -19
  91. package/utils/JsViewVueWidget/JsvScrollBox/index.js +0 -2
@@ -4,6 +4,8 @@ import { default as KeepFlags } from "./KeepFlags.ts"
4
4
  import JsvEnvBlocker from "./JsvEnvBlocker.vue"
5
5
  import { newNexus } from "./NexusNode"
6
6
  import { default as ActControlDebug } from "./ActorControl.ts"
7
+ import { GetSyncLinkManager, SyncLinkSource } from "./SyncLinkManager.ts"
8
+
7
9
 
8
10
  let FreeMoveDef = {
9
11
  ActEventDefine,
@@ -12,7 +14,9 @@ let FreeMoveDef = {
12
14
 
13
15
  let FreeMoveFunc = {
14
16
  newNexus,
15
- ActControlDebug
17
+ ActControlDebug,
18
+ GetSyncLinkManager,
19
+ SyncLinkSource
16
20
  }
17
21
 
18
22
  export {
@@ -1,6 +1,8 @@
1
1
  <!--
2
2
  * 【模块 export 内容】
3
3
  * JsvNinePatch:Vue高阶组件,.9图展示控件,该控件的原图要求为正方形,延展后可为长方形
4
+ * centerWidth和borderOutset传值比较抽象,若 imageDspWidth 和图片素材的原图尺寸一直,
5
+ * 则可以参考 samples/NinePatchTester 的样例图示
4
6
  * props说明:
5
7
  * style {Object} 同div的Style,通过width/height来控制.9图片延展后的显示尺寸,另外通过top/left控制坐标
6
8
  * imageUrl {String} (必填)显示图片的加载地址
@@ -19,7 +21,7 @@
19
21
  -->
20
22
 
21
23
  <script setup>
22
- import { ref, watchEffect, computed } from "vue";
24
+ import { ref, watchEffect, computed, shallowRef, onMounted } from "vue";
23
25
 
24
26
  const props = defineProps({
25
27
  style: {
@@ -42,6 +44,9 @@ const props = defineProps({
42
44
  onTransitionEnd: { type: Function },
43
45
  animation: { type: String },
44
46
  imageBlendType: { type: String, default: null },
47
+
48
+ // 获取实际div的句柄
49
+ onDivRef: { type: Function, default: null },
45
50
  });
46
51
 
47
52
  const isReady = () => {
@@ -92,10 +97,17 @@ watchEffect(() => {
92
97
  );
93
98
  }
94
99
  });
100
+
101
+ // 向外提出div的引用,因为v-if缘故,不能在mounted时输出
102
+ // 特别注意: 析构时, onDivRef会输出 null
103
+ function innerOnDivRef(ref) {
104
+ props.onDivRef?.(ref);
105
+ }
95
106
  </script>
96
107
 
97
108
  <template>
98
109
  <div
110
+ :ref="innerOnDivRef"
99
111
  v-if="isReady()"
100
112
  :style="{
101
113
  ...style,
@@ -8,16 +8,23 @@
8
8
  * width {number}, 当VERTICAL滑动模式时为选填,HORIZONTAL为必填
9
9
  * height {number}, 当HORIZONTAL滑动模式时为选填,VERTICAL为必填
10
10
  * }
11
- * mode {ScrollStyle.DrawerMode/ScrollStyle.PinMode}
11
+ * mode {ScrollBoxStyle.DrawerMode/ScrollBoxStyle.PinMode}
12
12
  * 选填, 非响应式, 默认为 PinMode
13
13
  * 运动模式选择, DrawerMode: 抽屉模式,内容尺寸大于固定底座
14
14
  * PinMode: 滚动杆模式,内容尺寸小于固定底座
15
15
  * direction {import VERTICAL/HORIZONTAL} (必填,非响应式) 滑动方向
16
16
  * enableFling {boolean} (选填,非响应式) 是否需要支持fling,默认为false
17
17
  * initPercent {Number} (选填,非响应式) 滑块起始位置,等同于mount后进行updatePercent()
18
+ * linkName {String} (选填,非响应式) 本滑动模块的名字,用于全局进行syncWith处理的关联名
19
+ * 注意: 如果不需要共享进度,不要声明,可以节省一些构造性能
20
+ * syncWith {String} (选填,响应式) 进度联动组件来源,内容为联动来源的linkName
21
+ * syncType {ScrollBoxStyle.SyncForward|ScrollType.SyncReverse}
22
+ * (选填,响应式) 决定syncWith的联动模式,当syncWith设置后才能生效
23
+ * SyncForward(默认值): 同进同退, mySelf = sourcePercent
24
+ * SyncReverse: 进退反向, mySelf = (1 - sourcePercent)
18
25
  *
19
26
  * template说明:
20
- * FfixedBox={boxWidth, boxHeight}: 以本组件底座左上角0,0对齐的一个slot
27
+ * FixedBox={boxWidth, boxHeight}: 以本组件底座左上角0,0对齐的一个slot
21
28
  * SliderBox={boxWidth, boxHeight}: 以滑块div的左上角0,0对齐的一个slot,
22
29
  *
23
30
  * expose函数说明:
@@ -26,16 +33,6 @@
26
33
  * updatePercent(percent:number) 设置滚动调位置(百分比),百分比 = (SliderTop - 底座Top) / Slider可滑动总区域
27
34
  * Slider可滑动总区域 = 底座Height - SliderHeight
28
35
  * 当为横向运动时,Top被Left代换,Height被Width代换
29
- * syncWith(otherScrollBox: JsvScrollBox, syncMode: ScrollStyle)
30
- * 本滚动条的进度跟随给定的滚动条的进度移动
31
- * otherScrollBox: 控制者
32
- * syncMode: 同步模式,有 SyncParallel, SyncRevert
33
- * addSubSync(view: div|JsvNinePatch, syncMode: ScrollStyle)
34
- * 将外部的div或者JsvNinePatch加入到同步尺寸同步改动器中。
35
- * view只能是div或者JsvNinePatch, 并且不能有style.animation的控制
36
- * 当SyncParallel模式时, 这个div的初始位置要和本组件的0,0对齐
37
- * 当SyncRevert模式时, 这个div的初始位置要和本组件尾部位置(0, height/width)对齐
38
- *
39
36
  *
40
37
  -->
41
38
 
@@ -80,13 +77,20 @@ import {
80
77
  shallowRef,
81
78
  watchEffect,
82
79
  onMounted,
80
+ onUnmounted,
83
81
  defineExpose,
84
82
  defineProps,
85
83
  } from "vue";
86
84
  import ActControl from "../../JsViewVueWidget/JsvFreeMoveActor/ActorControl";
87
85
  import { VERTICAL, HORIZONTAL } from "../../JsViewVueTools/ConstSymbol";
88
- import { ScrollStyle } from "./ScrollSymbol";
86
+ import { ScrollBoxStyle } from "./ScrollSymbol";
87
+ import { ScrollInnerStyle } from "./ScrollInnerSymbol";
89
88
  import { ForgeConst } from "../../JsViewVueTools/ForgeConstDefine";
89
+ import {
90
+ GetSyncLinkManager,
91
+ SyncLinkSource,
92
+ } from "../../JsViewVueWidget/JsvFreeMoveActor/SyncLinkManager";
93
+ import { newNexus, NexusNode } from "../JsvFreeMoveActor/NexusNode";
90
94
 
91
95
  let rProps = defineProps({
92
96
  // 底座的尺寸
@@ -108,11 +112,11 @@ let rProps = defineProps({
108
112
  },
109
113
 
110
114
  // 滑块模式
111
- // ScrollStyle.PinMode: 滑块小于底座
112
- // ScrollStyle.DrawerMode: 滑块大于底座
115
+ // ScrollBoxStyle.PinMode: 滑块小于底座
116
+ // ScrollBoxStyle.DrawerMode: 滑块大于底座
113
117
  mode: {
114
118
  type: Symbol,
115
- default: ScrollStyle.PinMode,
119
+ default: ScrollBoxStyle.PinMode,
116
120
  },
117
121
 
118
122
  // 初始进度条的进度
@@ -125,6 +129,21 @@ let rProps = defineProps({
125
129
  type: Boolean,
126
130
  default: false,
127
131
  },
132
+
133
+ linkName: {
134
+ type: String,
135
+ default: null,
136
+ },
137
+
138
+ syncWith: {
139
+ type: String,
140
+ default: null,
141
+ },
142
+
143
+ syncType: {
144
+ type: Symbol,
145
+ default: ScrollBoxStyle.SyncForward,
146
+ },
128
147
  });
129
148
 
130
149
  /** 本地常量 **/
@@ -133,17 +152,27 @@ const cMode = rProps.mode;
133
152
  const cInitPercent = rProps.initPercent;
134
153
  const cEnableFling = rProps.enableFling;
135
154
  const cSliderActor = new ActControl();
136
- const cFixedBoxActor = cMode == ScrollStyle.PinMode ? new ActControl() : null;
155
+ const cFixedBoxActor =
156
+ cMode == ScrollBoxStyle.PinMode ? new ActControl() : null;
157
+ const cLinkName = rProps.linkName;
158
+ const cSyncLinkManager = GetSyncLinkManager();
137
159
 
138
160
  // Actor condition group id(1~9可任意用)
139
161
  const cWallConditionGroup = 1;
140
162
  const cSensorConditionGroup = 2;
163
+ const cLinkConditionGroup = 3;
164
+ const cLinkMasterGroup = 4;
141
165
 
142
166
  /** 本地非响应式变量 **/
143
- let vMounted = false;
144
- let vHorizontalGap = 0;
145
- let vVerticalGap = 0;
146
- let vSubSyncList = [];
167
+ let vMounted: boolean = false;
168
+ let vHorizontalGap: number = 0;
169
+ let vVerticalGap: number = 0;
170
+ let vLinkProvide: SyncLinkSource | null = null; // 是否对外提供同步进度影响
171
+ let vWaitMasterLinkSourceReady: Promise<void> | null = null;
172
+ let vSyncWithNameCache: String | null = null; // 当前关联的SyncLinkSource的名称
173
+ let vSyncTypeCache: Symbol = ScrollBoxStyle.SyncForward;
174
+ let vSyncLinkNexusNode: NexusNode | null = null;
175
+ let vCurrentPercent: number = 0;
147
176
 
148
177
  /** 本地响应式变量 **/
149
178
  let rFixedBoxWidth = shallowRef(NaN);
@@ -153,6 +182,14 @@ let rSliderWidth = shallowRef(NaN);
153
182
  let rSliderHeight = shallowRef(NaN);
154
183
  let rSliderViewRef = shallowRef(null);
155
184
 
185
+ // 记录slider的活动范围
186
+ let rSliderEdgeBox = {
187
+ top: 0,
188
+ bottom: 0,
189
+ left: 0,
190
+ right: 0,
191
+ };
192
+
156
193
  watchEffect(() => {
157
194
  let fixedBoxSize = {
158
195
  width: rProps.style!.width,
@@ -173,7 +210,7 @@ watchEffect(() => {
173
210
 
174
211
  // 合理性校验
175
212
  if (
176
- cMode == ScrollStyle.PinMode &&
213
+ cMode == ScrollBoxStyle.PinMode &&
177
214
  (sliderSize.height > fixedBoxSize.height ||
178
215
  sliderSize.width > fixedBoxSize.width)
179
216
  ) {
@@ -183,7 +220,7 @@ watchEffect(() => {
183
220
  );
184
221
  return;
185
222
  } else if (
186
- cMode == ScrollStyle.DrawerMode &&
223
+ cMode == ScrollBoxStyle.DrawerMode &&
187
224
  (sliderSize.height < fixedBoxSize.height ||
188
225
  sliderSize.width < fixedBoxSize.width)
189
226
  ) {
@@ -205,49 +242,181 @@ watchEffect(() => {
205
242
  rSliderHeight.value = sliderSize.height;
206
243
  rFixedBoxWidth.value = fixedBoxSize.width;
207
244
  rFixedBoxHeight.value = fixedBoxSize.height;
208
-
209
245
  rebuildSliderSet();
210
246
  }
247
+
248
+ // 在 rebuildSliderSet 之后,确认syncWith是否变化,变化则重建参照的SyncLinkSource
249
+ if (
250
+ vSyncWithNameCache != rProps.syncWith ||
251
+ vSyncTypeCache != rProps.syncType
252
+ ) {
253
+ vSyncWithNameCache = rProps.syncWith;
254
+ vSyncTypeCache = rProps.syncType;
255
+ changeSyncLink(vSyncWithNameCache);
256
+ }
211
257
  });
212
258
 
259
+ function changeSyncLink(newSyncSourceName: String) {
260
+ // 清理原Link nexusNode
261
+ vSyncLinkNexusNode = null;
262
+ rebuildAckSync();
263
+
264
+ if (newSyncSourceName != null) {
265
+ // 创建新Source的Ready promise, 在确认目标节点存在后再获取NexusNode来创建condition
266
+ // 注意此Promise要在unMounted时通过UnListen进行反注册,才能规避内存泄漏
267
+ vWaitMasterLinkSourceReady = cSyncLinkManager
268
+ .WaitSourceMounted(newSyncSourceName)
269
+ .then(() => {
270
+ // 获取Link nexusNode。此引用不用专门释放,没有内存泄漏问题
271
+ vSyncLinkNexusNode =
272
+ cSyncLinkManager.GetSourceNexusNode(newSyncSourceName);
273
+ rebuildAckSync();
274
+ });
275
+ }
276
+ }
277
+
278
+ function rebuildAckSync() {
279
+ if (!vMounted) return;
280
+
281
+ // 清理老设定
282
+ cSliderActor.run((cmds) => {
283
+ return [cmds.state().removeConditionByGroup(cLinkConditionGroup)];
284
+ });
285
+
286
+ if (vSyncLinkNexusNode != null) {
287
+ // 创建运动跟随的condition
288
+ cSliderActor.run((cmds) => {
289
+ return [
290
+ cmds
291
+ .condition(cLinkConditionGroup, true)
292
+ .movementSync(vSyncLinkNexusNode!)
293
+ .then([
294
+ cmds
295
+ .action()
296
+ .ackMovementSync(
297
+ 0,
298
+ vHorizontalGap,
299
+ 0,
300
+ vVerticalGap,
301
+ 0b11,
302
+ vSyncTypeCache == ScrollBoxStyle.SyncForward ? 1 : 2
303
+ ),
304
+ ]),
305
+ ];
306
+ });
307
+ }
308
+ }
309
+
310
+ function rebuildSyncMaster() {
311
+ if (vLinkProvide != null) {
312
+ // 创建移动信息的发生器
313
+ cSliderActor.run((cmds) => {
314
+ return [
315
+ cmds.state().removeConditionByGroup(cLinkMasterGroup),
316
+ cmds
317
+ .state()
318
+ .startMovementSync(
319
+ vLinkProvide!.nexusNode,
320
+ 0,
321
+ vHorizontalGap,
322
+ 0,
323
+ vVerticalGap,
324
+ 0b11
325
+ ),
326
+ // 触发跟随节点记录进度
327
+ cmds
328
+ .condition(cLinkMasterGroup, true)
329
+ .onFlingEnd()
330
+ .then([
331
+ cmds
332
+ .state()
333
+ .fireNexusEvent(
334
+ vLinkProvide!.nexusNode,
335
+ ScrollInnerStyle.UpdatePercentNexusCode
336
+ ),
337
+ ]),
338
+ // 触发跟随节点记录进度
339
+ cmds
340
+ .condition(cLinkMasterGroup, true)
341
+ .onDragEnd()
342
+ .then([
343
+ cmds
344
+ .state()
345
+ .fireNexusEvent(
346
+ vLinkProvide!.nexusNode,
347
+ ScrollInnerStyle.UpdatePercentNexusCode
348
+ ),
349
+ ]),
350
+ ];
351
+ });
352
+ }
353
+ }
354
+
213
355
  function rebuildSliderSet() {
356
+ // 计算slider的活动区域
357
+ // 运动区域无论正负都通用的算法
358
+ vHorizontalGap = rFixedBoxWidth.value - rSliderWidth.value;
359
+ vVerticalGap = rFixedBoxHeight.value - rSliderHeight.value;
360
+
361
+ // 更新slider的活动范围
362
+ rSliderEdgeBox.left = vHorizontalGap > 0 ? 0 : vHorizontalGap;
363
+ rSliderEdgeBox.top = vVerticalGap > 0 ? 0 : vVerticalGap;
364
+ rSliderEdgeBox.right = vHorizontalGap < 0 ? 0 : vHorizontalGap;
365
+ rSliderEdgeBox.bottom = vVerticalGap < 0 ? 0 : vVerticalGap;
366
+
214
367
  if (vMounted) {
215
- // 计算slider的活动区域
216
- // 运动区域无论正负都通用的算法
217
- vHorizontalGap = rFixedBoxWidth.value - rSliderWidth.value;
218
- vVerticalGap = rFixedBoxHeight.value - rSliderHeight.value;
219
-
220
- cSliderActor.run([
221
- cSliderActor.state().removeConditionByGroup(cWallConditionGroup),
222
- cSliderActor
368
+ // 设置Actor的活动边界
369
+ cSliderActor.run((cmds) => [
370
+ cmds.state().removeConditionByGroup(cWallConditionGroup),
371
+ cmds
223
372
  .condition(cWallConditionGroup, true)
224
373
  .boxPosition(
225
- vHorizontalGap > 0 ? 0 : vHorizontalGap, // left
226
- vVerticalGap > 0 ? 0 : vVerticalGap, // top
227
- vHorizontalGap < 0 ? 0 : vHorizontalGap, // right
228
- vVerticalGap < 0 ? 0 : vVerticalGap // bottom
374
+ rSliderEdgeBox.left,
375
+ rSliderEdgeBox.top,
376
+ rSliderEdgeBox.right,
377
+ rSliderEdgeBox.bottom
229
378
  )!
230
- .then([cSliderActor.action().stopMoving(true)]),
379
+ .then([cmds.action().stopMoving(true)]),
380
+ // 跟进抬起时进度信息
381
+ cmds
382
+ .condition(cWallConditionGroup, true)
383
+ .onFlingEnd()
384
+ .then([
385
+ (pointInfo: any) => {
386
+ vCurrentPercent = positionToPercent(pointInfo);
387
+ },
388
+ ]),
389
+ // 跟进fling结束时的进度信息
390
+ cmds
391
+ .condition(cWallConditionGroup, true)
392
+ .onDragEnd()
393
+ .then([
394
+ (pointInfo: any) => {
395
+ vCurrentPercent = positionToPercent(pointInfo);
396
+ },
397
+ ]),
231
398
  ]);
399
+
400
+ // 尺寸变化时,重建Sync同步的信息
401
+ rebuildSyncMaster();
402
+ rebuildAckSync();
232
403
  }
233
404
  }
234
405
 
235
406
  // setSensor 函数声明
236
407
  function setSensor(callback: Function, sensitivity: number) {
237
- cSliderActor.run([
238
- cSliderActor.state().removeConditionByGroup(cSensorConditionGroup),
408
+ cSliderActor.run((cmds) => [
409
+ cmds.state().removeConditionByGroup(cSensorConditionGroup),
239
410
  ]);
240
411
  if (callback != null) {
241
- cSliderActor.run([
242
- cSliderActor
412
+ cSliderActor.run((cmds) => [
413
+ cmds
243
414
  .condition(cSensorConditionGroup, true)
244
415
  .onMovement(sensitivity) // 设置x或y移动超过12时才触发回调,以此减少回调的频次,规避js的性能影响
245
416
  .then([
246
417
  (pointInfo: any) => {
247
- let percent =
248
- cDirection == HORIZONTAL
249
- ? pointInfo.xPos / vHorizontalGap
250
- : pointInfo.yPos / vVerticalGap;
418
+ let percent: number = positionToPercent(pointInfo);
419
+ vCurrentPercent = percent;
251
420
  callback(percent, pointInfo.xPos, pointInfo.yPos);
252
421
  },
253
422
  ]),
@@ -255,6 +424,17 @@ function setSensor(callback: Function, sensitivity: number) {
255
424
  }
256
425
  }
257
426
 
427
+ // 内部函数,位置信息转成百分比信息
428
+ function positionToPercent(pointInfo: any): number {
429
+ let percent: number = 0;
430
+ if (cDirection == HORIZONTAL) {
431
+ percent = vHorizontalGap != 0 ? pointInfo.xPos / vHorizontalGap : 0;
432
+ } else {
433
+ percent = vVerticalGap != 0 ? pointInfo.yPos / vVerticalGap : 0;
434
+ }
435
+ return percent;
436
+ }
437
+
258
438
  // updatePercent 函数声明
259
439
  function updatePercent(percent: number) {
260
440
  let xPos: number = 0;
@@ -264,7 +444,12 @@ function updatePercent(percent: number) {
264
444
  } else {
265
445
  yPos = Math.floor(percent * vVerticalGap);
266
446
  }
267
- cSliderActor.run([cSliderActor.action().teleportTo(xPos, yPos)]);
447
+ cSliderActor.run((cmds) => [cmds.action().teleportTo(xPos, yPos)]);
448
+ vCurrentPercent = percent;
449
+ }
450
+
451
+ function currentPercent(): number {
452
+ return vCurrentPercent;
268
453
  }
269
454
 
270
455
  onMounted(() => {
@@ -291,18 +476,42 @@ onMounted(() => {
291
476
  let fixedBoxView = (rFixedViewRef.value as any).jsvGetProxyView();
292
477
  cFixedBoxActor.bindForgeView(fixedBoxView, true);
293
478
  fixedBoxView.DragEnables?.(ForgeConst.DragFlags.TOUCH_RECV_FIRST_START); // 仅激活touchDown即可捕获并触发 TouchAttractChild
294
- cFixedBoxActor.run([
295
- cFixedBoxActor.state().setTouchAttractChild(cSliderActor),
479
+ cFixedBoxActor.run((cmds) => [
480
+ cmds.state().setTouchAttractChild(cSliderActor),
296
481
  ]);
297
482
  }
298
483
 
484
+ // 创建提供同步信息来源的 SyncLinkSource,并登录到SyncLinkManager中(SourceOnMounted)
485
+ // 注意:此处理一定要在 onUnmounted 时进行 SourceOnUnmounted,才能规避内存泄漏
486
+ if (cLinkName != null) {
487
+ vLinkProvide = new SyncLinkSource(cLinkName, newNexus());
488
+ rebuildSyncMaster();
489
+ cSyncLinkManager.SourceOnMounted(vLinkProvide);
490
+ }
491
+
299
492
  // 设置滑动区域和关联区域
300
493
  rebuildSliderSet();
301
494
  });
302
495
 
496
+ onUnmounted(() => {
497
+ /** 关于LinkSource的释放 **/
498
+ // 释放作为linkSource master时的句柄
499
+ if (vLinkProvide != null) {
500
+ cSyncLinkManager.SourceOnUnmounted(cLinkName);
501
+ vLinkProvide = null;
502
+ }
503
+
504
+ // 释放作为linkSource slave时的句柄
505
+ if (vWaitMasterLinkSourceReady != null) {
506
+ cSyncLinkManager.UnListen(vWaitMasterLinkSourceReady);
507
+ vWaitMasterLinkSourceReady = null;
508
+ }
509
+ });
510
+
303
511
  defineExpose({
304
512
  setSensor,
305
513
  updatePercent,
514
+ currentPercent,
306
515
  });
307
516
  </script>
308
517