@vitalens/panel 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eric
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @vitalens/panel
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vitalens 可选性能看板 UI,基于 Vue 3。面板面向开发与验收环境,建议由宿主懒加载,不进入首屏。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @vitalens/panel
9
+ ```
10
+
11
+ `@vitalens/core`、`vue`、`echarts`、`tdesign-vue-next` 是 peerDependencies,需由宿主自行安装:
12
+
13
+ ```bash
14
+ pnpm add @vitalens/core vue echarts tdesign-vue-next
15
+ ```
16
+
17
+ ## 使用
18
+
19
+ 显式导入组件与样式,然后在模板中以 kebab-case 使用:
20
+
21
+ ```vue
22
+ <template>
23
+ <perf-panel :perf="perf" />
24
+ </template>
25
+
26
+ <script setup lang="ts">
27
+ import { createPerf } from '@vitalens/core';
28
+ import { PerfPanel } from '@vitalens/panel';
29
+ import '@vitalens/panel/style.css';
30
+
31
+ const perf = createPerf({
32
+ appId: 'my-app',
33
+ transport: { reporter: 'indexeddb' },
34
+ });
35
+ </script>
36
+ ```
37
+
38
+ 也可以直接通过 `records` 传入待展示的记录:
39
+
40
+ ```vue
41
+ <perf-panel :perf="perf" :records="records" />
42
+ ```
43
+
44
+ ## 功能
45
+
46
+ - **数据源**:`perf` 模式通过 `query()` 读取本地记录并订阅实时批次(1s 合并),
47
+ `records` 模式直接展示宿主注入的数据;两者可同时使用,按记录 id 去重。
48
+ - **概览**:LCP / INP / CLS / FCP / TTFB 的 p75、错误数、慢请求(≥1000ms)与长任务数;
49
+ 按 Core Web Vitals 标准阈值以 good / warn / poor 状态色着色,并展示阈值提示。
50
+ - **趋势**:按分钟或小时聚合的错误、请求、长任务与埋点折线图;ECharts 从
51
+ `echarts/core` 按需注册,页面隐藏时暂停实时刷新。
52
+ - **明细**:错误 / 请求 / 路由 / 资源 / 埋点五个 Tab,支持关键字筛选与本地分页(20 条/页);
53
+ 请求记录展示脱敏后的 query 参数,失败请求、慢路由、慢资源等按状态色标出。
54
+ - **视觉**:卡片式分区、sticky 表头、斑马纹与 hover、状态 chip、URL 等宽显示;
55
+ 样式全部 scoped,不注入全局样式。
56
+ - **数据操作**:刷新、导出 JSON、导入 JSON、清空本地数据(二次确认)、实时开关。
57
+ 导入、清空与实时开关在未提供 `perf` 时禁用。
58
+ - **隔离**:不读取宿主 store/auth/router;样式全部 scoped;通过 `onErrorCaptured`
59
+ 将渲染异常收敛为面板内兜底提示,不向宿主冒泡。
60
+
61
+ ## 按需加载
62
+
63
+ 面板依赖 ECharts,建议仅在开发/验收路由中动态加载,避免进入生产首屏:
64
+
65
+ ```ts
66
+ import { defineAsyncComponent } from 'vue';
67
+
68
+ const PerfPanel = defineAsyncComponent(() => import('@vitalens/panel').then((mod) => mod.PerfPanel));
69
+ ```
@@ -0,0 +1,8 @@
1
+ import { PerfRecord } from '@vitalens/core';
2
+ import { PerfPanelProps } from './types';
3
+ declare const __VLS_export: import('vue').DefineComponent<PerfPanelProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<PerfPanelProps> & Readonly<{}>, {
4
+ records: PerfRecord[];
5
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
8
+ //# sourceMappingURL=PerfPanel.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerfPanel.vue.d.ts","sourceRoot":"","sources":["../src/PerfPanel.vue"],"names":[],"mappings":"AAsQA;AA0rDA,OAAO,KAAK,EAAE,UAAU,EAAoC,MAAM,gBAAgB,CAAC;AAUnF,OAAO,KAAK,EAAyD,cAAc,EAAoB,MAAM,SAAS,CAAC;AAm7CvH,QAAA,MAAM,YAAY;;6EAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,24 @@
1
+ import { PerfRecord } from '@vitalens/core';
2
+ import { ComputedRef } from 'vue';
3
+ import { PerfOverview, TopListItem, TrendGranularity, TrendPoint } from '../types';
4
+ export interface UsePerfMetricsOptions {
5
+ records: () => readonly PerfRecord[];
6
+ /** Top 排行条数,默认 5。 */
7
+ topLimit?: number;
8
+ }
9
+ export interface UsePerfMetricsResult {
10
+ overview: ComputedRef<PerfOverview>;
11
+ trend: ComputedRef<TrendPoint[]>;
12
+ trendGranularity: ComputedRef<TrendGranularity>;
13
+ topRoutes: ComputedRef<TopListItem[]>;
14
+ topErrors: ComputedRef<TopListItem[]>;
15
+ topEvents: ComputedRef<TopListItem[]>;
16
+ }
17
+ /**
18
+ * 从记录集合派生概览、趋势与 Top 排行。
19
+ *
20
+ * 全部计算为纯内存聚合,记录数量由 panel 数据层限制在上限内;
21
+ * 不触发 DOM/存储访问,便于在宿主主线程之外按需复用。
22
+ */
23
+ export declare function usePerfMetrics(options: UsePerfMetricsOptions): UsePerfMetricsResult;
24
+ //# sourceMappingURL=usePerfMetrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePerfMetrics.d.ts","sourceRoot":"","sources":["../../src/composables/usePerfMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAGvC,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AAkBrG,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,SAAS,UAAU,EAAE,CAAC;IACrC,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACpC,KAAK,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC;IACjC,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;IACtC,SAAS,EAAE,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;IACtC,SAAS,EAAE,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;CACvC;AAkFD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CAiKnF"}
@@ -0,0 +1,28 @@
1
+ import { Perf, PerfRecord } from '@vitalens/core';
2
+ import { Ref } from 'vue';
3
+ export interface UsePerfRecordsOptions {
4
+ perf: () => Perf | undefined;
5
+ records: () => readonly PerfRecord[] | undefined;
6
+ appId: () => string | undefined;
7
+ }
8
+ export interface UsePerfRecordsResult {
9
+ records: Readonly<Ref<readonly PerfRecord[]>>;
10
+ loading: Readonly<Ref<boolean>>;
11
+ error: Readonly<Ref<string>>;
12
+ realtime: Readonly<Ref<boolean>>;
13
+ refresh: () => Promise<void>;
14
+ importFile: (file: Blob) => Promise<number>;
15
+ exportFile: () => Promise<Blob | null>;
16
+ clearLocal: () => Promise<boolean>;
17
+ setRealtime: (enabled: boolean) => void;
18
+ }
19
+ /**
20
+ * 面板数据源:查询本地记录、合并宿主注入记录,并按 1s 批量接收实时记录。
21
+ *
22
+ * 隔离约束:
23
+ * - 所有 perf 调用都由本 composable 兜底,不向宿主抛错;
24
+ * - 页面隐藏时暂停实时合并,避免后台任务与图表更新;
25
+ * - 卸载时退订并移除监听,避免泄漏。
26
+ */
27
+ export declare function usePerfRecords(options: UsePerfRecordsOptions): UsePerfRecordsResult;
28
+ //# sourceMappingURL=usePerfRecords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePerfRecords.d.ts","sourceRoot":"","sources":["../../src/composables/usePerfRecords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAa,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAY/B,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,IAAI,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,SAAS,UAAU,EAAE,GAAG,SAAS,CAAC;IACjD,KAAK,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC,CAAC;IAC9C,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAChC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IACvC,UAAU,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AA4CD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA0SnF"}
@@ -0,0 +1,3 @@
1
+ export { default as PerfPanel } from './PerfPanel.vue';
2
+ export type { DetailColumn, DetailColumnKind, DetailRow, DetailTab, OverviewCardModel, PerfOverview, PerfPanelFilters, PerfPanelProps, Tone, TopListItem, TrendGranularity, TrendPoint, VitalP75Map, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,WAAW,GACZ,MAAM,SAAS,CAAC"}