@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,64 @@
1
+ /**
2
+ * zeppos-timer.js
3
+ * @description An accurate timer for ZeppOS. 一个适用于ZeppOS的准确的计时器
4
+ * @version 1.0.0
5
+ * @date 2023/04/07
6
+ * @author XiaomaiTX
7
+ * @license MIT
8
+ * https://github.com/XiaomaiTX/zeppos-timer
9
+ *
10
+ * */
11
+ import { Time } from "@zos/sensor";
12
+
13
+ export class ZeppTimer {
14
+ constructor(callback, interval) {
15
+ this.callback = callback;
16
+ this.interval = interval;
17
+ this.timerId = null;
18
+ this.startTime = null;
19
+ this.nextTick = null;
20
+ this.time = new Time();
21
+ this.stopped = false
22
+ }
23
+
24
+ start(delay = 0) {
25
+ this.startTime = this.time.getTime() + delay;
26
+ this.nextTick = this.startTime + this.interval;
27
+ this.scheduleTick();
28
+ }
29
+
30
+ stop() {
31
+ this.stopped = true
32
+ this.timerId && clearTimeout(this.timerId);
33
+ }
34
+
35
+ scheduleTick() {
36
+ if(this.stopped) return;
37
+ const currentTime = this.time.getTime();
38
+ const delay = Math.max(0, this.nextTick - currentTime);
39
+ this.timerId = setTimeout(() => {
40
+ this.tick();
41
+ }, delay);
42
+ }
43
+
44
+ tick() {
45
+ const currentTime = this.time.getTime();
46
+
47
+ // 计算误差,确保计时器的准确性
48
+ const error = currentTime - this.nextTick;
49
+
50
+ if (error > this.interval) {
51
+ // 如果误差大于一个间隔时间,则将 nextTick 更新为当前时间
52
+ this.nextTick = currentTime;
53
+ } else {
54
+ // 否则将 nextTick 加上一个间隔时间
55
+ this.nextTick += this.interval;
56
+ }
57
+
58
+ // 调用回调函数
59
+ this.callback();
60
+
61
+ // 继续调度下一个 tick
62
+ this.scheduleTick();
63
+ }
64
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@x1a0ma17x/zeppos-fx",
3
+ "version": "2.0.3",
4
+ "description": "A library for providing simple animations in ZeppOS.",
5
+ "main": "index.js",
6
+ "directories": {
7
+ "example": "example"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/XiaomaiTX/zeppos-fx.git"
15
+ },
16
+ "keywords": [
17
+ "ZeppOS"
18
+ ],
19
+ "author": "XiaomaiTX",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/XiaomaiTX/zeppos-fx/issues"
23
+ },
24
+ "homepage": "https://github.com/XiaomaiTX/zeppos-fx#readme"
25
+ }
@@ -0,0 +1,10 @@
1
+ App({
2
+ globalData: {},
3
+ onCreate(options) {
4
+ console.log('app on create invoke')
5
+ },
6
+
7
+ onDestroy(options) {
8
+ console.log('app on destroy invoke')
9
+ }
10
+ })
@@ -0,0 +1,46 @@
1
+ {
2
+ "configVersion": "v3",
3
+ "app": {
4
+ "appId": 25966,
5
+ "appName": "Empty",
6
+ "appType": "app",
7
+ "version": {
8
+ "code": 1,
9
+ "name": "1.0.0"
10
+ },
11
+ "icon": "icon.png",
12
+ "vender": "zepp",
13
+ "description": "empty application"
14
+ },
15
+ "permissions": [],
16
+ "runtime": {
17
+ "apiVersion": {
18
+ "compatible": "3.0.0",
19
+ "target": "3.0.0",
20
+ "minVersion": "3.0"
21
+ }
22
+ },
23
+ "targets": {
24
+ "default": {
25
+ "module": {
26
+ "page": {
27
+ "pages": [
28
+ "page/index"
29
+ ]
30
+ }
31
+ },
32
+ "platforms": [
33
+ {
34
+ "st": "r",
35
+ "dw": 480
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ "i18n": {
41
+ "en-US": {
42
+ "appName": "Empty"
43
+ }
44
+ },
45
+ "defaultLanguage": "en-US"
46
+ }
@@ -0,0 +1 @@
1
+ /// <reference path="node_modules/@zeppos/device-types/dist/index.d.ts" />
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es6",
5
+ "checkJs": true
6
+ },
7
+ "exclude": ["node_modules", "**/node_modules/*"],
8
+ "files": ["node_modules/@zeppos/device-types/dist/index.d.ts"]
9
+ }
@@ -0,0 +1,325 @@
1
+ /**
2
+ * fx.js
3
+ * @description A library for providing animations in ZeppOS. 一个用于在ZeppOS中提供动画的库
4
+ * @version 3.0.0
5
+ * @date 2024/11/02
6
+ * @author XiaomaiTX
7
+ * @license MIT
8
+ * https://github.com/XiaomaiTX/zeppos-fx
9
+ *
10
+ * **/
11
+
12
+ export class Fx {
13
+ constructor(params) {
14
+ this.tracks = params.tracks;
15
+ this.metadata = params.metadata;
16
+ this.status = "stop";
17
+ }
18
+
19
+ start() {
20
+ if (this.status == "stop" || this.status == "pause") {
21
+ this.status = "start";
22
+ for (let i = 0; i < this.tracks.length; i++) {
23
+ let track = this.tracks[i];
24
+ }
25
+ }
26
+ }
27
+ tick(track) {
28
+ /**
29
+ * @param track
30
+ * @param track.progress 进度
31
+ * @param track.totalFrame 总帧数
32
+ */
33
+ if (
34
+ this.status == "start" &&
35
+ track.progress < track.totalFrame
36
+ ) {
37
+
38
+ }
39
+ }
40
+ stop() {
41
+ if (this.status != "stop") {
42
+ this.status = "stop";
43
+ }
44
+ }
45
+
46
+ restart() {
47
+ this.status = "start";
48
+ }
49
+ pause() {
50
+ if (this.status == "start") {
51
+ this.status = "pause";
52
+ }
53
+ }
54
+ getStatus() {
55
+ return this.status;
56
+ }
57
+ }
58
+ Fx.Styles = {
59
+ /**
60
+ * List of preset styles
61
+ * @example EXAMPLE: indexNumber,
62
+ *
63
+ * */
64
+ // TODO Add more style
65
+
66
+ // The following presets are available for reference https://easings.net/
67
+ // 以下预设可参考 https://easings.net/
68
+
69
+ LINEAR: function (now_x, begin, end, max_x) {
70
+ function math_func(x) {
71
+ return x;
72
+ }
73
+ return begin + (end - begin) * math_func(now_x / max_x);
74
+ },
75
+ EASE_IN_SINE: function (now_x, begin, end, max_x) {
76
+ function math_func(x) {
77
+ return 1 - cos((x * Math.PI) / 2);
78
+ }
79
+ return begin + (end - begin) * math_func(now_x / max_x);
80
+ },
81
+ EASE_OUT_SINE: function (now_x, begin, end, max_x) {
82
+ function math_func(x) {
83
+ return sin((x * Math.PI) / 2);
84
+ }
85
+ return begin + (end - begin) * math_func(now_x / max_x);
86
+ },
87
+ EASE_IN_OUT_SINE: function (now_x, begin, end, max_x) {
88
+ function math_func(x) {
89
+ return -(cos(Math.PI * x) - 1) / 2;
90
+ }
91
+ return begin + (end - begin) * math_func(now_x / max_x);
92
+ },
93
+ EASE_IN_QUAD: function (now_x, begin, end, max_x) {
94
+ function math_func(x) {
95
+ return x * x;
96
+ }
97
+ return begin + (end - begin) * math_func(now_x / max_x);
98
+ },
99
+ EASE_OUT_QUAD: function (now_x, begin, end, max_x) {
100
+ function math_func(x) {
101
+ return 1 - (1 - x) * (1 - x);
102
+ }
103
+ return begin + (end - begin) * math_func(now_x / max_x);
104
+ },
105
+ EASE_IN_OUT_QUAD: function (now_x, begin, end, max_x) {
106
+ function math_func(x) {
107
+ return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
108
+ }
109
+ return begin + (end - begin) * math_func(now_x / max_x);
110
+ },
111
+ EASE_IN_CUBIC: function (now_x, begin, end, max_x) {
112
+ function math_func(x) {
113
+ return x * x * x;
114
+ }
115
+ return begin + (end - begin) * math_func(now_x / max_x);
116
+ },
117
+ EASE_OUT_CUBIC: function (now_x, begin, end, max_x) {
118
+ function math_func(x) {
119
+ return 1 - Math.pow(1 - x, 3);
120
+ }
121
+ return begin + (end - begin) * math_func(now_x / max_x);
122
+ },
123
+ EASE_IN_OUT_CUBIC: function (now_x, begin, end, max_x) {
124
+ function math_func(x) {
125
+ return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
126
+ }
127
+ return begin + (end - begin) * math_func(now_x / max_x);
128
+ },
129
+ EASE_IN_QUART: function (now_x, begin, end, max_x) {
130
+ function math_func(x) {
131
+ return x * x * x * x;
132
+ }
133
+ return begin + (end - begin) * math_func(now_x / max_x);
134
+ },
135
+ EASE_OUT_QUART: function (now_x, begin, end, max_x) {
136
+ function math_func(x) {
137
+ return 1 - Math.pow(1 - x, 4);
138
+ }
139
+ return begin + (end - begin) * math_func(now_x / max_x);
140
+ },
141
+ EASE_IN_OUT_QUART: function (now_x, begin, end, max_x) {
142
+ function math_func(x) {
143
+ return x < 0.5
144
+ ? 8 * x * x * x * x
145
+ : 1 - Math.pow(-2 * x + 2, 4) / 2;
146
+ }
147
+ return begin + (end - begin) * math_func(now_x / max_x);
148
+ },
149
+ EASE_IN_QUINT: function (now_x, begin, end, max_x) {
150
+ function math_func(x) {
151
+ return x * x * x * x * x;
152
+ }
153
+ return begin + (end - begin) * math_func(now_x / max_x);
154
+ },
155
+ EASE_OUT_QUINT: function (now_x, begin, end, max_x) {
156
+ function math_func(x) {
157
+ return 1 - Math.pow(1 - x, 4);
158
+ }
159
+ return begin + (end - begin) * math_func(now_x / max_x);
160
+ },
161
+ EASE_IN_OUT_QUINT: function (now_x, begin, end, max_x) {
162
+ function math_func(x) {
163
+ return x < 0.5
164
+ ? 16 * x * x * x * x * x
165
+ : 1 - Math.pow(-2 * x + 2, 5) / 2;
166
+ }
167
+ return begin + (end - begin) * math_func(now_x / max_x);
168
+ },
169
+ EASE_IN_EXPO: function (now_x, begin, end, max_x) {
170
+ function math_func(x) {
171
+ return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
172
+ }
173
+ return begin + (end - begin) * math_func(now_x / max_x);
174
+ },
175
+ EASE_OUT_EXPO: function (now_x, begin, end, max_x) {
176
+ function math_func(x) {
177
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
178
+ }
179
+ return begin + (end - begin) * math_func(now_x / max_x);
180
+ },
181
+ EASE_IN_OUT_EXPO: function (now_x, begin, end, max_x) {
182
+ function math_func(x) {
183
+ return x === 0
184
+ ? 0
185
+ : x === 1
186
+ ? 1
187
+ : x < 0.5
188
+ ? Math.pow(2, 20 * x - 10) / 2
189
+ : (2 - Math.pow(2, -20 * x + 10)) / 2;
190
+ }
191
+ return begin + (end - begin) * math_func(now_x / max_x);
192
+ },
193
+ EASE_IN_CIRC: function (now_x, begin, end, max_x) {
194
+ function math_func(x) {
195
+ return 1 - Math.sqrt(1 - Math.pow(x, 2));
196
+ }
197
+ return begin + (end - begin) * math_func(now_x / max_x);
198
+ },
199
+ EASE_OUT_CIRC: function (now_x, begin, end, max_x) {
200
+ function math_func(x) {
201
+ return Math.sqrt(1 - Math.pow(x - 1, 2));
202
+ }
203
+ return begin + (end - begin) * math_func(now_x / max_x);
204
+ },
205
+ EASE_IN_OUT_CIRC: function (now_x, begin, end, max_x) {
206
+ function math_func(x) {
207
+ return x < 0.5
208
+ ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2
209
+ : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
210
+ }
211
+ return begin + (end - begin) * math_func(now_x / max_x);
212
+ },
213
+ EASE_IN_BACK: function (now_x, begin, end, max_x) {
214
+ function math_func(x) {
215
+ return 1.70158 + 1 * x * x * x - 1.70158 * x * x;
216
+ }
217
+ return begin + (end - begin) * math_func(now_x / max_x);
218
+ },
219
+ EASE_OUT_BACK: function (now_x, begin, end, max_x) {
220
+ function math_func(x) {
221
+ return (
222
+ 1 +
223
+ 1.70158 +
224
+ 1 * Math.pow(x - 1, 3) +
225
+ 1.70158 * Math.pow(x - 1, 2)
226
+ );
227
+ }
228
+ return begin + (end - begin) * math_func(now_x / max_x);
229
+ },
230
+ EASE_IN_OUT_BACK: function (now_x, begin, end, max_x) {
231
+ function math_func(x) {
232
+ return x < 0.5
233
+ ? (Math.pow(2 * x, 2) *
234
+ ((1.70158 * 1.525 + 1) * 2 * x - 1.70158 * 1.525)) /
235
+ 2
236
+ : (Math.pow(2 * x - 2, 2) *
237
+ ((1.70158 * 1.525 + 1) * (x * 2 - 2) + 1.70158 * 1.525) +
238
+ 2) /
239
+ 2;
240
+ }
241
+ return begin + (end - begin) * math_func(now_x / max_x);
242
+ },
243
+ EASE_IN_ELASTIC: function (now_x, begin, end, max_x) {
244
+ function math_func(x) {
245
+ return x === 0
246
+ ? 0
247
+ : x === 1
248
+ ? 1
249
+ : -Math.pow(2, 10 * x - 10) *
250
+ sin(((x * 10 - 10.75) * (2 * Math.PI)) / 3);
251
+ }
252
+ return begin + (end - begin) * math_func(now_x / max_x);
253
+ },
254
+ EASE_OUT_ELASTIC: function (now_x, begin, end, max_x) {
255
+ function math_func(x) {
256
+ return x === 0
257
+ ? 0
258
+ : x === 1
259
+ ? 1
260
+ : Math.pow(2, -10 * x) *
261
+ sin(((x * 10 - 0.75) * (2 * Math.PI)) / 3) +
262
+ 1;
263
+ }
264
+ return begin + (end - begin) * math_func(now_x / max_x);
265
+ },
266
+ EASE_IN_OUT_ELASTIC: function (now_x, begin, end, max_x) {
267
+ function math_func(x) {
268
+ return x === 0
269
+ ? 0
270
+ : x === 1
271
+ ? 1
272
+ : x < 0.5
273
+ ? -(
274
+ Math.pow(2, 20 * x - 10) *
275
+ sin(((20 * x - 11.125) * (2 * Math.PI)) / 4.5)
276
+ ) / 2
277
+ : (Math.pow(2, -20 * x + 10) *
278
+ sin(((20 * x - 11.125) * (2 * Math.PI)) / 4.5)) /
279
+ 2 +
280
+ 1;
281
+ }
282
+ return begin + (end - begin) * math_func(now_x / max_x);
283
+ },
284
+ EASE_IN_BOUNCE: function (now_x, begin, end, max_x) {
285
+ function math_func(x) {
286
+ return 1 - Fx.Styles.bounceOut(1 - x);
287
+ }
288
+ return begin + (end - begin) * math_func(now_x / max_x);
289
+ },
290
+ EASE_OUT_BOUNCE: function (now_x, begin, end, max_x) {
291
+ function math_func(x) {
292
+ return Fx.Styles.bounceOut(x);
293
+ }
294
+ return begin + (end - begin) * math_func(now_x / max_x);
295
+ },
296
+ EASE_IN_OUT_BOUNCE: function (now_x, begin, end, max_x) {
297
+ function math_func(x) {
298
+ return x < 0.5
299
+ ? (1 - Fx.Styles.bounceOut(1 - 2 * x)) / 2
300
+ : (1 + Fx.Styles.bounceOut(2 * x - 1)) / 2;
301
+ }
302
+ return begin + (end - begin) * math_func(now_x / max_x);
303
+ },
304
+ bounceOut: function (x) {
305
+ /**
306
+ * Returns the bounce out result of x
307
+ * @param {number} x
308
+ * @returns {number}
309
+ */
310
+ const n1 = 7.5625;
311
+ const d1 = 2.75;
312
+
313
+ if (x < 1 / d1) {
314
+ return n1 * x * x;
315
+ } else if (x < 2 / d1) {
316
+ return n1 * (x -= 1.5 / d1) * x + 0.75;
317
+ } else if (x < 2.5 / d1) {
318
+ return n1 * (x -= 2.25 / d1) * x + 0.9375;
319
+ } else {
320
+ return n1 * (x -= 2.625 / d1) * x + 0.984375;
321
+ }
322
+ },
323
+ };
324
+
325
+ export default Fx;
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "empty",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "app.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "devDependencies": {
12
+ "@zeppos/device-types": "^3.0.0"
13
+ }
14
+ }
@@ -0,0 +1,60 @@
1
+ import { Fx } from "../libs/fx";
2
+ import * as hmUI from "@zos/ui";
3
+
4
+ export const ANIM_PROFILE = {
5
+ metadata: {
6
+ version: 1,
7
+ author: "XiaomaiTX",
8
+ default_config: {
9
+ track: {
10
+ startTime: 0,
11
+ },
12
+ frame: {
13
+ fps: 60,
14
+ time: 1,
15
+ style: Fx.Styles.EASE_IN_OUT_QUAD,
16
+ },
17
+ },
18
+ },
19
+ tracks: [
20
+ {
21
+ config: {
22
+ startTime: 0,
23
+ },
24
+ frames: [
25
+ {
26
+ delay: 0,
27
+ fps: 60,
28
+ time: 1,
29
+ style: Fx.Styles.EASE_IN_OUT_QUAD,
30
+ init_func: () => {
31
+ console.log("init");
32
+ const text = hmUI.createWidget(hmUI.widget.TEXT, {
33
+ x: 0,
34
+ y: 0,
35
+ w: 100,
36
+ h: 100,
37
+ text: "Hello World",
38
+ color: 0xff3232,
39
+ });
40
+ return text;
41
+ },
42
+ runtime_func: (wgtObj, progress) => {
43
+ let begin = 0;
44
+ let end = 100;
45
+ console.log(begin + (end - begin) * progress);
46
+ wgtObj.setProperty(
47
+ hmUI.prop.X,
48
+ begin + (end - begin) * progress
49
+ );
50
+ return wgtObj;
51
+ },
52
+
53
+ callback_func: (wgtObj) => {
54
+ console.log("callback");
55
+ },
56
+ },
57
+ ],
58
+ },
59
+ ],
60
+ };
@@ -0,0 +1,2 @@
1
+ msgid "example"
2
+ msgstr "This is an example in device"
@@ -0,0 +1,13 @@
1
+ import { getText } from '@zos/i18n'
2
+ import * as Styles from 'zosLoader:./index.[pf].layout.js'
3
+ import { Fx } from '../libs/fx';
4
+ import { ANIM_PROFILE } from './anim';
5
+
6
+ Page({
7
+ build() {
8
+ const anim = new Fx(ANIM_PROFILE);
9
+
10
+ anim.start();
11
+ console.log(anim.getStatus());
12
+ }
13
+ })
@@ -0,0 +1,6 @@
1
+ import { px } from "@zos/utils";
2
+
3
+ export const TEXT_STYLE = {
4
+ x: px(0),
5
+ y: px(0),
6
+ }