cbvirtua 1.0.23 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/queue.js ADDED
@@ -0,0 +1,124 @@
1
+ function promiseWithResolvers() {
2
+ let resolve;
3
+ let reject;
4
+ const promise = new Promise(
5
+ (res, rej) => {
6
+ // Executed synchronously!
7
+ resolve = res;
8
+ reject = rej;
9
+ });
10
+ return { promise, resolve, reject };
11
+ }
12
+
13
+ class PromiseQueue {
14
+ constructor() {
15
+ const { promise, resolve } = Promise.withResolvers();
16
+ this.frontPromise = promise;
17
+ this.backResolve = resolve;
18
+ this.i = 0
19
+ }
20
+ put() {
21
+ const { resolve, promise } = Promise.withResolvers();
22
+ // By resolving, we add another (pending) element
23
+ // to the end of the queue
24
+ this.i++
25
+ const value = this.i
26
+ this.backResolve({ value, promise });
27
+ this.backResolve = resolve;
28
+ }
29
+ get() {
30
+ return this.frontPromise.then(
31
+ (next) => {
32
+ this.frontPromise = next.promise;
33
+ return next.value;
34
+ }
35
+ );
36
+ }
37
+ }
38
+
39
+
40
+ let test
41
+ async function aa() {
42
+ const queue = new PromiseQueue();
43
+ setTimeout(() => {
44
+ queue.put()
45
+ }, 1000)
46
+ let i = await queue.get()
47
+ console.log('i1', i)
48
+ test = queue
49
+ let i2 = await queue.get()
50
+ console.log('i2', i2)
51
+
52
+ }
53
+
54
+ aa()
55
+
56
+
57
+ setTimeout(() => {
58
+ test.put()
59
+ }, 3000)
60
+
61
+ class AsyncIterQueue {
62
+ #frontPromise;
63
+ #backResolve;
64
+ constructor() {
65
+ const { promise, resolve } = Promise.withResolvers();
66
+ this.#frontPromise = promise;
67
+ this.#backResolve = resolve;
68
+ }
69
+ put(value) {
70
+ if (this.#backResolve === null) {
71
+ throw new Error('Queue is closed');
72
+ }
73
+ const { resolve, promise } = Promise.withResolvers();
74
+ this.#backResolve({ done: false, value, promise });
75
+ this.#backResolve = resolve;
76
+ }
77
+ close() {
78
+ this.#backResolve(
79
+ { done: true, value: undefined, promise: null }
80
+ );
81
+ this.#backResolve = null;
82
+ }
83
+ next() {
84
+ if (this.#frontPromise === null) {
85
+ return Promise.resolve({ done: true });
86
+ }
87
+ return this.#frontPromise.then(
88
+ (next) => {
89
+ this.#frontPromise = next.promise;
90
+ return { value: next.value, done: next.done };
91
+ }
92
+ );
93
+ }
94
+ [Symbol.asyncIterator]() {
95
+ return this;
96
+ }
97
+ }
98
+
99
+ { // Putting before async iteration
100
+ const queue = new AsyncIterQueue();
101
+ queue.put('one');
102
+ queue.put('two');
103
+ queue.close();
104
+ assert.deepEqual(
105
+ await Array.fromAsync(queue),
106
+ ['one', 'two']
107
+ );
108
+ }
109
+ { // Async iteration before putting
110
+ const queue = new AsyncIterQueue();
111
+ setTimeout(
112
+ // Runs after `await` pauses the current execution context
113
+ () => {
114
+ queue.put('one');
115
+ queue.put('two');
116
+ queue.close();
117
+ },
118
+ 0
119
+ );
120
+ assert.deepEqual(
121
+ await Array.fromAsync(queue),
122
+ ['one', 'two']
123
+ );
124
+ }
@@ -0,0 +1,85 @@
1
+ <view class="rect submit_btn flexbox_auto" id="btn" style="top:{{top}}px;left:{{left}}px;" bindtap="onSubmit" bindtouchmove="onTouchmove" bindtouchstart="onTouchStart">
2
+ 提交
3
+ </view>
4
+ ———
5
+ let startX = 0 // 获取手指初始坐标
6
+ let startY = 0
7
+ let x = 0 // 获得盒子原来的位置
8
+ let y = 0
9
+ let cSys = {} // 当前系统配置
10
+ let btnsRect = [] // 拖拽元素宽高
11
+ let defaultH = 100 // 缺省高度
12
+ let defaultW = 100 // 缺省宽度
13
+
14
+ Component({
15
+ lifetimes: {
16
+ ready: function () {
17
+ const query = wx.createSelectorQuery().in(this)
18
+ query.select('#btn').boundingClientRect(res => {
19
+ cSys = wx.getSystemInfoSync()
20
+ btnsRect = [res.width, res.height]
21
+ const top = Math.floor(cSys.windowHeight - btnsRect[1] - defaultH)
22
+ const left = Math.floor(cSys.windowWidth - btnsRect[0] - defaultW)
23
+ this.setData({
24
+ top,
25
+ left
26
+ })
27
+ }).exec();
28
+ },
29
+ },
30
+ data: {
31
+ top: 0,
32
+ left: 0,
33
+ },
34
+ methods: {
35
+ onTouchStart (e) {
36
+ // 获取手指初始坐标
37
+ startX = e.changedTouches[0].pageX;
38
+ startY = e.changedTouches[0].pageY;
39
+ x = e.currentTarget.offsetLeft;
40
+ y = e.currentTarget.offsetTop;
41
+ },
42
+ onTouchmove (e) {
43
+ // 计算手指的移动距离:手指移动之后的坐标减去手指初始的坐标
44
+ const moveX = e.changedTouches[0].pageX - startX;
45
+ const moveY = e.changedTouches[0].pageY - startY;
46
+ // 移动盒子 盒子原来的位置 + 手指移动的距离
47
+ const top = Math.floor(Math.min(Math.max(0, y + moveY), cSys.windowHeight - btnsRect[1]))
48
+ const left = Math.floor(Math.min(Math.max(0, x + moveX), cSys.windowWidth - btnsRect[0]))
49
+ this.setData({
50
+ top,
51
+ left
52
+ })
53
+ },
54
+ onSubmit () {
55
+ console.warn('提交');
56
+ }
57
+ },
58
+ })
59
+ ————————————————
60
+ page{
61
+ width: 100%;
62
+ height: 100%;
63
+ background-color: #F5F5F5;
64
+ }
65
+
66
+ .submit_btn{
67
+ background: rgba(0, 0, 0, .05);
68
+ border-radius: 10rpx;
69
+ border: 2rpx solid #999999;
70
+ color: #999999;
71
+ font-size: 28rpx;
72
+ position: absolute;
73
+ }
74
+
75
+ .flexbox_auto{
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ }
80
+
81
+ .rect{
82
+ height: 100rpx;
83
+ width: 120rpx;
84
+ }
85
+ ————————————————
package/vue-i18n-dev.zip DELETED
Binary file