@quicktvui/web-cli 1.0.1 → 1.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.
@@ -15,6 +15,7 @@ import {
15
15
  APP_NAME,
16
16
  IJKPlayerComponent,
17
17
  } from '@quicktvui/web-renderer'
18
+ import { setupGlobalErrorHandler } from './error-badge.js'
18
19
 
19
20
  // 初始化 async localStorage
20
21
  initAsyncLocalStorage()
@@ -39,6 +40,14 @@ applyAllPatches(engine)
39
40
  global.__TV_FOCUS_MANAGER__ = new TVFocusManager()
40
41
  console.log('[Web Renderer] TVFocusManager initialized')
41
42
 
43
+ // 初始化错误提示组件(在 DOM 准备好后)
44
+ if (document.readyState === 'loading') {
45
+ document.addEventListener('DOMContentLoaded', () => setupGlobalErrorHandler())
46
+ } else {
47
+ setupGlobalErrorHandler()
48
+ }
49
+ console.log('[Web Renderer] Error badge initialized')
50
+
42
51
  // 注入全局 CSS
43
52
  const styleEl = document.createElement('style')
44
53
  styleEl.id = 'web-platform-reset'
@@ -0,0 +1,410 @@
1
+ /**
2
+ * 自定义错误提示组件
3
+ * 在右上角显示红色角标,点击可查看错误详情
4
+ */
5
+
6
+ class ErrorBadge {
7
+ constructor() {
8
+ this.errors = []
9
+ this.isExpanded = false
10
+ this.badge = null
11
+ this.panel = null
12
+ this.container = null
13
+ this.init()
14
+ }
15
+
16
+ init() {
17
+ // 创建容器
18
+ this.container = document.createElement('div')
19
+ this.container.id = 'qt-error-badge-container'
20
+ this.container.innerHTML = `
21
+ <style>
22
+ #qt-error-badge-container {
23
+ position: fixed;
24
+ top: 0;
25
+ right: 0;
26
+ z-index: 999999;
27
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
28
+ }
29
+ #qt-error-badge {
30
+ display: none;
31
+ position: fixed;
32
+ top: 16px;
33
+ right: 16px;
34
+ width: 32px;
35
+ height: 32px;
36
+ background: linear-gradient(135deg, #ff4444, #cc0000);
37
+ border-radius: 50%;
38
+ cursor: pointer;
39
+ box-shadow: 0 4px 12px rgba(204, 0, 0, 0.4);
40
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
41
+ z-index: 999999;
42
+ }
43
+ #qt-error-badge:hover {
44
+ transform: scale(1.1);
45
+ box-shadow: 0 6px 16px rgba(204, 0, 0, 0.5);
46
+ }
47
+ #qt-error-badge.visible {
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ }
52
+ #qt-error-count {
53
+ color: white;
54
+ font-size: 14px;
55
+ font-weight: bold;
56
+ min-width: 20px;
57
+ text-align: center;
58
+ }
59
+ #qt-error-badge-icon {
60
+ display: none;
61
+ color: white;
62
+ font-size: 18px;
63
+ font-weight: bold;
64
+ }
65
+ #qt-error-panel {
66
+ display: none;
67
+ position: fixed;
68
+ top: 56px;
69
+ right: 16px;
70
+ width: 420px;
71
+ max-height: 400px;
72
+ background: #1e1e1e;
73
+ border-radius: 8px;
74
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
75
+ overflow: hidden;
76
+ z-index: 999998;
77
+ }
78
+ #qt-error-panel.visible {
79
+ display: block;
80
+ }
81
+ #qt-error-panel-header {
82
+ display: flex;
83
+ align-items: center;
84
+ justify-content: space-between;
85
+ padding: 12px 16px;
86
+ background: #2d2d2d;
87
+ border-bottom: 1px solid #404040;
88
+ }
89
+ #qt-error-panel-title {
90
+ color: #ff6b6b;
91
+ font-size: 14px;
92
+ font-weight: 600;
93
+ }
94
+ #qt-error-panel-close {
95
+ background: none;
96
+ border: none;
97
+ color: #888;
98
+ font-size: 20px;
99
+ cursor: pointer;
100
+ padding: 0;
101
+ line-height: 1;
102
+ }
103
+ #qt-error-panel-close:hover {
104
+ color: #fff;
105
+ }
106
+ #qt-error-panel-clear {
107
+ background: none;
108
+ border: 1px solid #666;
109
+ color: #aaa;
110
+ font-size: 12px;
111
+ cursor: pointer;
112
+ padding: 4px 8px;
113
+ border-radius: 4px;
114
+ margin-right: 8px;
115
+ }
116
+ #qt-error-panel-clear:hover {
117
+ border-color: #ff6b6b;
118
+ color: #ff6b6b;
119
+ }
120
+ #qt-error-list {
121
+ max-height: 340px;
122
+ overflow-y: auto;
123
+ padding: 0;
124
+ margin: 0;
125
+ list-style: none;
126
+ }
127
+ #qt-error-list::-webkit-scrollbar {
128
+ width: 6px;
129
+ }
130
+ #qt-error-list::-webkit-scrollbar-track {
131
+ background: #1e1e1e;
132
+ }
133
+ #qt-error-list::-webkit-scrollbar-thumb {
134
+ background: #444;
135
+ border-radius: 3px;
136
+ }
137
+ #qt-error-list::-webkit-scrollbar-thumb:hover {
138
+ background: #555;
139
+ }
140
+ .qt-error-item {
141
+ padding: 12px 16px;
142
+ border-bottom: 1px solid #2d2d2d;
143
+ cursor: pointer;
144
+ transition: background 0.2s ease;
145
+ }
146
+ .qt-error-item:hover {
147
+ background: #2a2a2a;
148
+ }
149
+ .qt-error-item:last-child {
150
+ border-bottom: none;
151
+ }
152
+ .qt-error-time {
153
+ color: #888;
154
+ font-size: 11px;
155
+ margin-bottom: 4px;
156
+ }
157
+ .qt-error-message {
158
+ color: #ff6b6b;
159
+ font-size: 13px;
160
+ line-height: 1.4;
161
+ word-break: break-all;
162
+ }
163
+ .qt-error-stack {
164
+ display: none;
165
+ color: #aaa;
166
+ font-size: 11px;
167
+ margin-top: 8px;
168
+ padding: 8px;
169
+ background: #252525;
170
+ border-radius: 4px;
171
+ white-space: pre-wrap;
172
+ word-break: break-all;
173
+ max-height: 120px;
174
+ overflow-y: auto;
175
+ }
176
+ .qt-error-item.expanded .qt-error-stack {
177
+ display: block;
178
+ }
179
+ .qt-error-empty {
180
+ padding: 24px;
181
+ text-align: center;
182
+ color: #666;
183
+ font-size: 13px;
184
+ }
185
+ </style>
186
+ <div id="qt-error-badge">
187
+ <span id="qt-error-badge-icon">!</span>
188
+ <span id="qt-error-count">0</span>
189
+ </div>
190
+ <div id="qt-error-panel">
191
+ <div id="qt-error-panel-header">
192
+ <span id="qt-error-panel-title">运行时错误</span>
193
+ <div>
194
+ <button id="qt-error-panel-clear">清除全部</button>
195
+ <button id="qt-error-panel-close">&times;</button>
196
+ </div>
197
+ </div>
198
+ <ul id="qt-error-list"></ul>
199
+ </div>
200
+ `
201
+
202
+ document.head.appendChild(this.container.querySelector('style'))
203
+ document.body.appendChild(this.container)
204
+
205
+ // 获取元素引用
206
+ this.badge = document.getElementById('qt-error-badge')
207
+ this.panel = document.getElementById('qt-error-panel')
208
+ this.countEl = document.getElementById('qt-error-count')
209
+ this.listEl = document.getElementById('qt-error-list')
210
+ this.iconEl = document.getElementById('qt-error-badge-icon')
211
+
212
+ // 绑定事件
213
+ this.badge.addEventListener('click', () => this.toggle())
214
+ document.getElementById('qt-error-panel-close').addEventListener('click', () => this.hide())
215
+ document.getElementById('qt-error-panel-clear').addEventListener('click', () => this.clear())
216
+
217
+ // 点击外部关闭
218
+ document.addEventListener('click', (e) => {
219
+ if (this.isExpanded && !this.container.contains(e.target)) {
220
+ this.hide()
221
+ }
222
+ })
223
+ }
224
+
225
+ addError(error) {
226
+ const errorInfo = {
227
+ id: Date.now(),
228
+ time: new Date().toLocaleTimeString(),
229
+ message: this.getErrorMessage(error),
230
+ stack: this.getErrorStack(error),
231
+ }
232
+
233
+ this.errors.push(errorInfo)
234
+ this.updateBadge()
235
+ this.renderErrors()
236
+
237
+ // 首次错误时闪烁提示
238
+ if (this.errors.length === 1) {
239
+ this.flash()
240
+ }
241
+ }
242
+
243
+ getErrorMessage(error) {
244
+ if (typeof error === 'string') return error
245
+ if (error && typeof error === 'object') {
246
+ if (error.message) return error.message
247
+ if (error.error && error.error.message) return error.error.message
248
+ try {
249
+ return JSON.stringify(error)
250
+ } catch (e) {
251
+ return '[object Object]'
252
+ }
253
+ }
254
+ return String(error)
255
+ }
256
+
257
+ getErrorStack(error) {
258
+ if (error && error.error && error.error.stack) return error.error.stack
259
+ if (error && error.stack) return error.stack
260
+ return ''
261
+ }
262
+
263
+ updateBadge() {
264
+ const count = this.errors.length
265
+ if (count > 0) {
266
+ this.badge.classList.add('visible')
267
+ this.countEl.textContent = count > 99 ? '99+' : count
268
+ this.countEl.style.display = 'inline'
269
+ this.iconEl.style.display = 'none'
270
+ } else {
271
+ this.badge.classList.remove('visible')
272
+ }
273
+ }
274
+
275
+ renderErrors() {
276
+ if (this.errors.length === 0) {
277
+ this.listEl.innerHTML = '<li class="qt-error-empty">暂无错误</li>'
278
+ return
279
+ }
280
+
281
+ this.listEl.innerHTML = this.errors
282
+ .map(
283
+ (err) => `
284
+ <li class="qt-error-item" data-id="${err.id}">
285
+ <div class="qt-error-time">${err.time}</div>
286
+ <div class="qt-error-message">${this.escapeHtml(err.message)}</div>
287
+ ${
288
+ err.stack
289
+ ? `<div class="qt-error-stack">${this.escapeHtml(this.formatStack(err.stack))}</div>`
290
+ : ''
291
+ }
292
+ </li>
293
+ `
294
+ )
295
+ .join('')
296
+
297
+ // 点击展开/收起详情
298
+ this.listEl.querySelectorAll('.qt-error-item').forEach((item) => {
299
+ item.addEventListener('click', () => {
300
+ item.classList.toggle('expanded')
301
+ })
302
+ })
303
+ }
304
+
305
+ formatStack(stack) {
306
+ // 简化堆栈信息,只保留关键部分
307
+ const lines = stack.split('\n')
308
+ const relevantLines = lines.filter((line) => {
309
+ return (
310
+ line.includes('.vue') ||
311
+ line.includes('.js') ||
312
+ line.includes('.ts') ||
313
+ line.includes('at ') ||
314
+ !line.trim()
315
+ )
316
+ })
317
+ return relevantLines.slice(0, 10).join('\n')
318
+ }
319
+
320
+ escapeHtml(str) {
321
+ const div = document.createElement('div')
322
+ div.textContent = str
323
+ return div.innerHTML
324
+ }
325
+
326
+ toggle() {
327
+ if (this.isExpanded) {
328
+ this.hide()
329
+ } else {
330
+ this.show()
331
+ }
332
+ }
333
+
334
+ show() {
335
+ this.isExpanded = true
336
+ this.panel.classList.add('visible')
337
+ }
338
+
339
+ hide() {
340
+ this.isExpanded = false
341
+ this.panel.classList.remove('visible')
342
+ }
343
+
344
+ clear() {
345
+ this.errors = []
346
+ this.updateBadge()
347
+ this.renderErrors()
348
+ this.hide()
349
+ }
350
+
351
+ flash() {
352
+ // 首次错误时闪烁提示
353
+ let count = 0
354
+ const flash = () => {
355
+ if (count >= 6) return
356
+ this.badge.style.transform = count % 2 === 0 ? 'scale(1.2)' : 'scale(1)'
357
+ count++
358
+ setTimeout(flash, 100)
359
+ }
360
+ flash()
361
+ }
362
+ }
363
+
364
+ // 创建全局实例
365
+ let errorBadgeInstance = null
366
+
367
+ function initErrorBadge() {
368
+ if (!errorBadgeInstance) {
369
+ errorBadgeInstance = new ErrorBadge()
370
+ }
371
+ return errorBadgeInstance
372
+ }
373
+
374
+ // 捕获全局错误
375
+ function setupGlobalErrorHandler() {
376
+ const badge = initErrorBadge()
377
+
378
+ // 捕获 JavaScript 错误
379
+ window.addEventListener('error', (event) => {
380
+ badge.addError({
381
+ message: event.message,
382
+ stack: event.error?.stack || '',
383
+ })
384
+ // 不阻止默认行为,错误仍会输出到控制台
385
+ })
386
+
387
+ // 捕获 Promise 未处理错误
388
+ window.addEventListener('unhandledrejection', (event) => {
389
+ badge.addError({
390
+ message: event.reason?.message || String(event.reason),
391
+ stack: event.reason?.stack || '',
392
+ })
393
+ })
394
+
395
+ // 捕获 Vue 错误
396
+ if (window.Vue) {
397
+ window.Vue.config.errorHandler = (err, vm, info) => {
398
+ badge.addError({
399
+ message: `[Vue] ${err.message}`,
400
+ stack: err.stack || '',
401
+ })
402
+ console.error('[Vue Error]', err, info)
403
+ }
404
+ }
405
+
406
+ return badge
407
+ }
408
+
409
+ // 导出
410
+ export { ErrorBadge, initErrorBadge, setupGlobalErrorHandler }
@@ -183,7 +183,7 @@ module.exports = {
183
183
  },
184
184
  ],
185
185
  client: {
186
- overlay: { errors: true, warnings: false },
186
+ overlay: false,
187
187
  },
188
188
  },
189
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "CLI tool for QuickTVUI web development - zero configuration",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",
@@ -45,16 +45,31 @@
45
45
  overflow: hidden;
46
46
  background-color: #1a1a1a;
47
47
  }
48
+ /* 主容器 - 包含所有内容,统一缩放 */
49
+ #main-container {
50
+ width: 1920px;
51
+ height: 1080px;
52
+ position: absolute;
53
+ top: 0;
54
+ left: 0;
55
+ background-color: #26292F;
56
+ visibility: hidden;
57
+ }
48
58
  #app {
49
59
  width: 1920px !important;
50
60
  height: 1080px !important;
51
- transform-origin: top left;
52
61
  background-color: #26292F;
53
- visibility: hidden;
54
62
  }
55
- /* 返回按钮样式 */
63
+ /* Force all direct children of #app to be 1920x1080 */
64
+ #app > * {
65
+ width: 1920px !important;
66
+ height: 1080px !important;
67
+ position: relative !important;
68
+ overflow: hidden !important;
69
+ }
70
+ /* 返回按钮样式 - 相对于 main-container */
56
71
  #web-back-btn {
57
- position: fixed;
72
+ position: absolute;
58
73
  z-index: 99999;
59
74
  width: 48px;
60
75
  height: 48px;
@@ -67,6 +82,8 @@
67
82
  justify-content: center;
68
83
  transition: all 0.2s ease;
69
84
  backdrop-filter: blur(10px);
85
+ left: 20px;
86
+ top: 20px;
70
87
  }
71
88
  #web-back-btn:hover {
72
89
  background: rgba(255, 255, 255, 0.2);
@@ -85,13 +102,6 @@
85
102
  stroke-linecap: round;
86
103
  stroke-linejoin: round;
87
104
  }
88
- /* Force all direct children of #app to be 1920x1080 */
89
- #app > * {
90
- width: 1920px !important;
91
- height: 1080px !important;
92
- position: relative !important;
93
- overflow: hidden !important;
94
- }
95
105
  /* TV Focus styles */
96
106
  [focusable="true"], [data-focusable="true"] {
97
107
  cursor: pointer;
@@ -117,35 +127,27 @@
117
127
  document.addEventListener('DOMContentLoaded', fixAppDimensions);
118
128
  window.addEventListener('load', fixAppDimensions);
119
129
 
120
- // Scale the app to fit the viewport
130
+ // Scale the main-container to fit the viewport
121
131
  function scaleApp() {
122
- var app = document.getElementById('app');
123
- if (app) {
124
- app.style.setProperty('width', TV_WIDTH + 'px', 'important');
125
- app.style.setProperty('height', TV_HEIGHT + 'px', 'important');
132
+ var container = document.getElementById('main-container');
133
+ if (container) {
134
+ container.style.setProperty('width', TV_WIDTH + 'px');
135
+ container.style.setProperty('height', TV_HEIGHT + 'px');
126
136
 
127
137
  var scaleX = _originalInnerWidth / TV_WIDTH;
128
138
  var scaleY = _originalInnerHeight / TV_HEIGHT;
129
139
  var scale = Math.min(scaleX, scaleY);
130
- app.style.transform = 'scale(' + scale + ')';
140
+ container.style.transformOrigin = 'top left';
141
+ container.style.transform = 'scale(' + scale + ')';
131
142
  var offsetX = (_originalInnerWidth - TV_WIDTH * scale) / 2;
132
143
  var offsetY = (_originalInnerHeight - TV_HEIGHT * scale) / 2;
133
- app.style.marginLeft = offsetX + 'px';
134
- app.style.marginTop = offsetY + 'px';
144
+ container.style.left = '0';
145
+ container.style.top = '0';
146
+ container.style.marginLeft = offsetX + 'px';
147
+ container.style.marginTop = offsetY + 'px';
135
148
 
136
- // Show the app after positioning
137
- app.style.visibility = 'visible';
138
-
139
- // 更新返回按钮位置,相对于 #app 左上角
140
- var btn = document.getElementById('web-back-btn');
141
- if (btn) {
142
- var btnSize = 48 * scale;
143
- var btnMargin = 20 * scale;
144
- btn.style.width = btnSize + 'px';
145
- btn.style.height = btnSize + 'px';
146
- btn.style.left = (offsetX + btnMargin) + 'px';
147
- btn.style.top = (offsetY + btnMargin) + 'px';
148
- }
149
+ // Show the container after positioning
150
+ container.style.visibility = 'visible';
149
151
  }
150
152
  }
151
153
 
@@ -160,13 +162,17 @@
160
162
  </script>
161
163
  </head>
162
164
  <body>
163
- <div id="app"></div>
164
- <!-- Web 返回按钮 - 动态定位 -->
165
- <button id="web-back-btn" title="返回">
166
- <svg viewBox="0 0 24 24">
167
- <polyline points="15 18 9 12 15 6"></polyline>
168
- </svg>
169
- </button>
165
+ <!-- 主容器 - 所有内容都在这里,统一缩放 -->
166
+ <div id="main-container">
167
+ <!-- 返回按钮 -->
168
+ <button id="web-back-btn" title="返回">
169
+ <svg viewBox="0 0 24 24">
170
+ <polyline points="15 18 9 12 15 6"></polyline>
171
+ </svg>
172
+ </button>
173
+ <!-- 应用容器 -->
174
+ <div id="app"></div>
175
+ </div>
170
176
  <script>
171
177
  // 返回按钮点击事件
172
178
  document.getElementById('web-back-btn').addEventListener('click', function() {