@x1a0ma17x/zeppos-fx 2.0.3

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 (46) hide show
  1. package/.z18n.config.json +11 -0
  2. package/License +21 -0
  3. package/README.md +190 -0
  4. package/README_zh-CN.md +196 -0
  5. package/example/app-side/i18n/en-US.po +2 -0
  6. package/example/app-side/index.js +13 -0
  7. package/example/app.js +10 -0
  8. package/example/app.json +52 -0
  9. package/example/assets/default.b/icon.png +0 -0
  10. package/example/assets/default.r/icon.png +0 -0
  11. package/example/assets/default.s/icon.png +0 -0
  12. package/example/global.d.ts +1 -0
  13. package/example/jsconfig.json +9 -0
  14. package/example/package.json +14 -0
  15. package/example/page/i18n/en-US.po +2 -0
  16. package/example/page/i18n/fr-FR.po +4 -0
  17. package/example/page/i18n/ru-RU.po +4 -0
  18. package/example/page/i18n/zh-CN.po +2 -0
  19. package/example/page/i18n/zh-TW.po +4 -0
  20. package/example/page/index.anim.js +37 -0
  21. package/example/page/index.js +19 -0
  22. package/example/page/index.r.layout.js +6 -0
  23. package/example/page/index.style.js +13 -0
  24. package/example/setting/i18n/en-US.po +2 -0
  25. package/example/setting/index.js +7 -0
  26. package/fx.js +623 -0
  27. package/fx.js.png +0 -0
  28. package/index.js +1 -0
  29. package/old/v1.0/fx.js +706 -0
  30. package/old/v1.0/smoothTimer.js +92 -0
  31. package/old/v2.0/fx.js +761 -0
  32. package/old/v2.0/zeppos_timer.js +64 -0
  33. package/package.json +25 -0
  34. package/src/example/app.js +10 -0
  35. package/src/example/app.json +46 -0
  36. package/src/example/assets/default.b/icon.png +0 -0
  37. package/src/example/assets/default.r/icon.png +0 -0
  38. package/src/example/assets/default.s/icon.png +0 -0
  39. package/src/example/global.d.ts +1 -0
  40. package/src/example/jsconfig.json +9 -0
  41. package/src/example/libs/fx.js +325 -0
  42. package/src/example/package.json +14 -0
  43. package/src/example/page/anim.js +60 -0
  44. package/src/example/page/i18n/en-US.po +2 -0
  45. package/src/example/page/index.js +13 -0
  46. package/src/example/page/index.r.layout.js +6 -0
@@ -0,0 +1,92 @@
1
+ // smoothTimer.js 稳定计时器 用于解决Zepp OS timer计时器不准的问题
2
+ // @author CuberQAQ
3
+ // @date 2022/12/24
4
+ // Open Source Lisence: MIT <https://opensource.org/licenses/mit-license.php>
5
+
6
+ const SMOOTH_TIMER_TEST_CIRCLE = 1
7
+ const SMOOTH_TIMER_SAFE_TIME = 30
8
+ const hmTime = hmSensor.createSensor(hmSensor.id.TIME)
9
+
10
+
11
+ export class SmoothTimer {
12
+ /**
13
+ * Create a smooth timer.
14
+ * 创建一个稳定的计时器
15
+ * @param {number} delay Time to start. 延迟执行的时间。
16
+ * @param {number} circle The Loop Circle(ms). 循环周期(单位:毫秒)。
17
+ * @param {(option: any) => void} func Function Callback. 回调函数。
18
+ * @param {*} option As the param when call the Callback Function. 回调函数的参数
19
+ * @param {SmoothTimer.modes} mode The mode of smoothTimer. 稳定计时器的模式 @see SmoothTimer.modes
20
+ * @returns {SmoothTimer} Smooth Timer Object. Will be used when delete timer. 稳定计时器实例,删除计时器时用到
21
+ * @author CuberQAQ
22
+ */
23
+ constructor(delay, circle, func, option, mode) {
24
+ this._lastUtc_ = hmTime.utc + delay - circle
25
+ //if (frequency != undefined) { circle = Math.round(1000 / frequency) }
26
+ if (circle == undefined)
27
+ return null
28
+ this.mode = mode || SmoothTimer.modes.DYNAMIC_SMOOTH
29
+ this._circle_ = circle
30
+ this._hmTimer_ = timer.createTimer(
31
+ 0,
32
+ SMOOTH_TIMER_TEST_CIRCLE,
33
+ param => {
34
+ // 检测是否到达指定时间
35
+ if (hmTime.utc - this._lastUtc_ >= circle) { // 到达并执行
36
+ if(this.mode == SmoothTimer.modes.MAX_LIMIT) {
37
+ this._lastUtc_ = hmTime.utc - 0.75
38
+ }
39
+ else if (this.mode == SmoothTimer.modes.DYNAMIC_SMOOTH) {
40
+ this._lastUtc_ += circle // 更新上一次执行的时间戳
41
+ }
42
+
43
+ func(param) // 执行
44
+ }
45
+ // // 检测是否到达指定时间
46
+ // while(hmTime.utc - this._lastUtc_ >= circle + SMOOTH_TIMER_SAFE_TIME) { // 到达并执行
47
+ // this._lastUtc_ += circle // 更新上一次执行的时间戳
48
+ // func(param) // 执行
49
+ // }
50
+ },
51
+ option
52
+ )
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Smooth Timer Mode 稳定计时器运行模式
58
+ *
59
+ * DYNAMIC_SMOOTH: 动态稳定 Try to make total callback times smooth 尝试稳定总回调次数
60
+ *
61
+ * MAX_LIMIT: 限制速度 Can't run faster then setting 在限定范围内运行
62
+ */
63
+ SmoothTimer.modes = {
64
+ DYNAMIC_SMOOTH: 1, // 动态稳定
65
+ MAX_LIMIT: 2, // 限制速度
66
+ }
67
+
68
+ /**
69
+ * Create a smooth timer.
70
+ * 创建一个稳定的计时器
71
+ * @param {number} delay Time to start. 延迟执行的时间。
72
+ * @param {number} circle The Loop Circle(ms). 循环周期(单位:毫秒)。
73
+ * @param {(option: any) => void} func Function Callback. 回调函数。
74
+ * @param {*} option As the param when call the Callback Function. 回调函数的参数
75
+ * @param {SmoothTimer.modes|undefined} mode The mode of smoothTimer. 稳定计时器的模式 @see SmoothTimer.modes
76
+ * @returns {SmoothTimer} Smooth Timer Object. Will be used when delete timer. 稳定计时器实例,删除计时器时用到
77
+ * @author CuberQAQ
78
+ */
79
+ export function createSmoothTimer(delay, circle, func, option, mode) {
80
+ return new SmoothTimer(delay, circle, func, option, mode)
81
+ }
82
+
83
+ /**
84
+ * Delete a smooth timer.
85
+ * 删除已启用的稳定计时器
86
+ * @param {SmoothTimer} instance Smooth Timer Instance. 已启用的SmoothTimer实例
87
+ * @returns {boolean} If successfully stop. 是否成功删除
88
+ */
89
+ export function stopSmoothTimer(instance) {
90
+ if (instance._hmTimer_) { timer.stopTimer(instance._hmTimer_); return true }
91
+ return false
92
+ }