@aicupa/plugin-balance 1.0.6 → 1.0.8

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": "@aicupa/plugin-balance",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Show time balance ratio between temporary and current tasks",
5
5
  "main": "./service",
6
6
  "view": "./view",
package/service.js CHANGED
@@ -32,7 +32,7 @@ module.exports = createPlugin((api) => {
32
32
  let total = 0;
33
33
 
34
34
  const today = new Date();
35
- today.setHours(0, 0, 0, 0);
35
+ today.setHours(8, 0, 0, 0);
36
36
  const startOfDayTimestamp = today.getTime();
37
37
 
38
38
  if (!node) return total;
@@ -46,7 +46,13 @@ module.exports = createPlugin((api) => {
46
46
  n.todo.end > n.todo.start
47
47
  ) {
48
48
  if (n.todo.keep) continue;
49
- if (n.todo.start < startOfDayTimestamp) continue;
49
+
50
+ let end = n.todo.end;
51
+ let start = n.todo.start;
52
+
53
+ if (start < startOfDayTimestamp) {
54
+ start = startOfDayTimestamp;
55
+ }
50
56
  total += n.todo.end - n.todo.start;
51
57
  }
52
58
  if (Array.isArray(n.children)) {
@@ -124,10 +130,12 @@ module.exports = createPlugin((api) => {
124
130
  const tempTime = collectDoneTime(tempNode);
125
131
  const currentTime = collectDoneTime(currentNode);
126
132
  const percent = Math.round((tempTime / (currentTime + tempTime)) * 100);
133
+ const tempContent = tempNode?.todo?.content || '';
134
+ const currentContent = currentNode?.todo?.content || '';
127
135
 
128
136
  return {
129
137
  ok: true,
130
- result: { percent, tempTime, currentTime },
138
+ result: { percent, tempTime, currentTime, tempContent, currentContent },
131
139
  };
132
140
  },
133
141
  };
package/view/index.html CHANGED
@@ -71,18 +71,41 @@
71
71
  }
72
72
 
73
73
  .balance-bar-track {
74
- height: 4px;
75
- border-radius: 2px;
74
+ height: 16px;
75
+ border-radius: 8px;
76
76
  background: rgba(128, 128, 128, 0.15);
77
77
  overflow: hidden;
78
+ position: relative;
78
79
  }
79
80
 
80
81
  .balance-bar-fill {
81
82
  height: 100%;
82
- border-radius: 3px;
83
+ border-radius: 8px;
83
84
  transition: width 0.3s ease, background 0.3s ease;
84
85
  }
85
86
 
87
+ .bar-label {
88
+ position: absolute;
89
+ top: 50%;
90
+ transform: translateY(-50%);
91
+ font-size: 9px;
92
+ opacity: 0.8;
93
+ white-space: nowrap;
94
+ overflow: hidden;
95
+ text-overflow: ellipsis;
96
+ pointer-events: none;
97
+ padding: 0 4px;
98
+ }
99
+
100
+ .bar-label-left {
101
+ left: 0;
102
+ text-align: center;
103
+ }
104
+
105
+ .bar-label-right {
106
+ text-align: center;
107
+ }
108
+
86
109
  .balance-ratio {
87
110
  font-size: 11px;
88
111
  opacity: 0.7;
@@ -134,6 +157,8 @@
134
157
  <div class="balance-bar-wrap">
135
158
  <div class="balance-bar-track">
136
159
  <div class="balance-bar-fill" id="barFill" style="width:0%"></div>
160
+ <span class="bar-label bar-label-left" id="labelLeft"></span>
161
+ <span class="bar-label bar-label-right" id="labelRight"></span>
137
162
  </div>
138
163
  </div>
139
164
  <span class="balance-ratio" id="ratio">0%</span>
@@ -180,6 +205,8 @@
180
205
  const currentInput = document.getElementById('currentId')
181
206
  const barFill = document.getElementById('barFill')
182
207
  const ratioEl = document.getElementById('ratio')
208
+ const labelLeft = document.getElementById('labelLeft')
209
+ const labelRight = document.getElementById('labelRight')
183
210
  const focusSection = document.getElementById('focusSection')
184
211
  const focusList = document.getElementById('focusList')
185
212
  let debounceTimer = null
@@ -210,8 +237,14 @@
210
237
  const pct = Math.min(r.percent || 0, 100)
211
238
  barFill.style.width = pct + '%'
212
239
  var h = Math.round(120 * (1 - pct / 100))
213
- barFill.style.background = 'hsl(' + h + ', 55%, 65%)'
214
- ratioEl.textContent = pct + '%'
240
+ barFill.style.background = 'hsla(' + h + ', 55%, 65%, 0.25)'
241
+ var offset = pct - 50
242
+ ratioEl.textContent = (offset > 0 ? '+' : '') + offset + '%'
243
+ labelLeft.textContent = r.tempContent || ''
244
+ labelLeft.style.width = pct + '%'
245
+ labelRight.textContent = r.currentContent || ''
246
+ labelRight.style.left = pct + '%'
247
+ labelRight.style.width = (100 - pct) + '%'
215
248
  }
216
249
  } catch (_) { }
217
250