transone-chart 0.1.2
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/README.md +181 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/miniprogram.d.ts +44 -0
- package/dist/adapters/native.d.ts +28 -0
- package/dist/adapters/types.d.ts +27 -0
- package/dist/adapters/web.d.ts +13 -0
- package/dist/charts/bar.d.ts +25 -0
- package/dist/charts/index.d.ts +4 -0
- package/dist/charts/line.d.ts +20 -0
- package/dist/charts/pie.d.ts +14 -0
- package/dist/charts/radar.d.ts +16 -0
- package/dist/component.d.ts +41 -0
- package/dist/core/axis.d.ts +47 -0
- package/dist/core/canvas.d.ts +61 -0
- package/dist/core/chart.d.ts +69 -0
- package/dist/core/layout.d.ts +58 -0
- package/dist/core/legend.d.ts +26 -0
- package/dist/core/scale.d.ts +67 -0
- package/dist/core/text.d.ts +20 -0
- package/dist/factory.d.ts +22 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +49 -0
- package/dist/types.d.ts +180 -0
- package/lib/adapters/index.ts +18 -0
- package/lib/adapters/miniprogram.ts +146 -0
- package/lib/adapters/native.ts +39 -0
- package/lib/adapters/types.ts +44 -0
- package/lib/adapters/web.ts +41 -0
- package/lib/charts/bar.ts +270 -0
- package/lib/charts/index.ts +4 -0
- package/lib/charts/line.ts +153 -0
- package/lib/charts/pie.ts +110 -0
- package/lib/charts/radar.ts +166 -0
- package/lib/component.ts +149 -0
- package/lib/core/axis.ts +174 -0
- package/lib/core/canvas.ts +130 -0
- package/lib/core/chart.ts +322 -0
- package/lib/core/layout.ts +221 -0
- package/lib/core/legend.ts +94 -0
- package/lib/core/scale.ts +183 -0
- package/lib/core/text.ts +70 -0
- package/lib/factory.ts +62 -0
- package/lib/index.ts +69 -0
- package/lib/types.ts +218 -0
- package/package.json +55 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图表布局计算:在给定画布尺寸内,按 title / legend / 坐标轴标签区
|
|
3
|
+
* 逐层扣除,得到最终绘图区(plot)。
|
|
4
|
+
*
|
|
5
|
+
* 布局只依赖注入的文本测量函数,不接触 Canvas 上下文本身,
|
|
6
|
+
* 保持纯逻辑可测。
|
|
7
|
+
*/
|
|
8
|
+
import type { LegendOption, TitleOption } from '../types';
|
|
9
|
+
export interface Box {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Padding {
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
left: number;
|
|
20
|
+
}
|
|
21
|
+
export interface LayoutInput {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
title?: TitleOption;
|
|
25
|
+
/** 图例配置(已解析 show/position)。 */
|
|
26
|
+
legend?: LegendOption;
|
|
27
|
+
/** 图例项名称列表(用于测量总宽度)。 */
|
|
28
|
+
legendItems?: readonly string[];
|
|
29
|
+
/** 数值轴刻度标签(测量最大宽度)。 */
|
|
30
|
+
valueLabels?: readonly string[];
|
|
31
|
+
/** 类目轴标签(测量最大宽度/高度)。 */
|
|
32
|
+
categoryLabels?: readonly string[];
|
|
33
|
+
/** 横向布局(横向柱状图):类目轴占左侧、数值轴占底部。 */
|
|
34
|
+
horizontal?: boolean;
|
|
35
|
+
/** 基础内边距,默认 { top: 12, right: 16, bottom: 12, left: 16 }。 */
|
|
36
|
+
basePadding?: Partial<Padding>;
|
|
37
|
+
}
|
|
38
|
+
export interface LayoutResult {
|
|
39
|
+
/** 绘图区(含网格与数据系列)。 */
|
|
40
|
+
plot: Box;
|
|
41
|
+
/** 数值轴标签区(横轴图中在左侧,横向图中在底部)。 */
|
|
42
|
+
valueAxisBox: Box;
|
|
43
|
+
/** 类目轴标签区(横轴图中在底部,横向图中在左侧)。 */
|
|
44
|
+
categoryAxisBox: Box;
|
|
45
|
+
/** 标题占用区(若存在)。 */
|
|
46
|
+
titleBox: Box | null;
|
|
47
|
+
/** 图例占用区(若存在)。 */
|
|
48
|
+
legendBox: Box | null;
|
|
49
|
+
padding: Padding;
|
|
50
|
+
}
|
|
51
|
+
export type MeasureTextFn = (text: string) => number;
|
|
52
|
+
/**
|
|
53
|
+
* 计算完整布局。规则:
|
|
54
|
+
* - title 固定顶部
|
|
55
|
+
* - legend:top → title 之下;bottom → 底部;right → 最右侧
|
|
56
|
+
* - 数值轴标签区与类目轴标签区按 horizontal 互换左右/底部
|
|
57
|
+
*/
|
|
58
|
+
export declare function computeLayout(input: LayoutInput, measure: MeasureTextFn): LayoutResult;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图例绘制:色块 + 文本。
|
|
3
|
+
* - top / bottom:横向单行居中排布
|
|
4
|
+
* - right:纵向排布
|
|
5
|
+
*/
|
|
6
|
+
import type { ICanvas2D } from './canvas';
|
|
7
|
+
import type { Box } from './layout';
|
|
8
|
+
export interface LegendItem {
|
|
9
|
+
name: string;
|
|
10
|
+
color: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LegendDrawOptions {
|
|
13
|
+
box: Box;
|
|
14
|
+
items: readonly LegendItem[];
|
|
15
|
+
position?: 'top' | 'bottom' | 'right';
|
|
16
|
+
fontSize?: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
markerSize?: number;
|
|
19
|
+
itemGap?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class LegendDrawer {
|
|
22
|
+
private readonly ctx;
|
|
23
|
+
constructor(ctx: ICanvas2D);
|
|
24
|
+
draw(options: LegendDrawOptions): void;
|
|
25
|
+
private drawItem;
|
|
26
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 比例尺:把数据域(domain)映射到像素范围(range)。
|
|
3
|
+
*
|
|
4
|
+
* - LinearScale:数值 → 像素,自动 nice 刻度(0.5 / 1 / 2 / 5 步进)
|
|
5
|
+
* - CategoryScale:类目索引 → 像素带(band),供柱状图计算柱宽
|
|
6
|
+
*
|
|
7
|
+
* 纯函数与轻量类实现,零平台依赖,便于单元测试。
|
|
8
|
+
*/
|
|
9
|
+
/** 数值域映射接口。 */
|
|
10
|
+
export interface LinearScaleOptions {
|
|
11
|
+
/** 数据最小值(未指定则按数据自动 nice)。 */
|
|
12
|
+
min?: number;
|
|
13
|
+
/** 数据最大值(未指定则按数据自动 nice)。 */
|
|
14
|
+
max?: number;
|
|
15
|
+
/** 期望刻度分段数,默认 5。 */
|
|
16
|
+
splitCount?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ScaleResult {
|
|
19
|
+
/** 映射后的像素坐标(已夹取到 range 内)。 */
|
|
20
|
+
scale(value: number): number;
|
|
21
|
+
/** nice 后的实际最小值。 */
|
|
22
|
+
min: number;
|
|
23
|
+
/** nice 后的实际最大值。 */
|
|
24
|
+
max: number;
|
|
25
|
+
/** 刻度值数组(含 min/max)。 */
|
|
26
|
+
ticks: number[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 计算 nice 刻度:把任意 [min, max] 数据范围规整为"美观"范围与刻度。
|
|
30
|
+
* 步进从 1 / 2 / 5 × 10^n 中选择,保证刻度间距整齐。
|
|
31
|
+
*/
|
|
32
|
+
export declare function niceTicks(rawMin: number, rawMax: number, splitCount?: number): {
|
|
33
|
+
min: number;
|
|
34
|
+
max: number;
|
|
35
|
+
step: number;
|
|
36
|
+
ticks: number[];
|
|
37
|
+
};
|
|
38
|
+
/** 线性比例尺:domain → [rangeStart, rangeEnd],自动 nice。 */
|
|
39
|
+
export declare class LinearScale {
|
|
40
|
+
readonly min: number;
|
|
41
|
+
readonly max: number;
|
|
42
|
+
readonly ticks: number[];
|
|
43
|
+
readonly step: number;
|
|
44
|
+
private readonly rangeStart;
|
|
45
|
+
private readonly rangeEnd;
|
|
46
|
+
constructor(dataMin: number, dataMax: number, rangeStart: number, rangeEnd: number, options?: LinearScaleOptions);
|
|
47
|
+
/** 数值 → 像素坐标(反向轴传 rangeEnd > rangeStart 即自然反转)。 */
|
|
48
|
+
scale(value: number): number;
|
|
49
|
+
}
|
|
50
|
+
/** 类目比例尺:N 个类目 → range 内均分带(band)。 */
|
|
51
|
+
export declare class CategoryScale {
|
|
52
|
+
readonly categories: readonly unknown[];
|
|
53
|
+
/** 每个类目带的像素宽度。 */
|
|
54
|
+
readonly bandWidth: number;
|
|
55
|
+
/** 类目带之间的间距占比(0~1),默认 0.35。 */
|
|
56
|
+
readonly innerGapRatio: number;
|
|
57
|
+
private readonly rangeStart;
|
|
58
|
+
constructor(categories: readonly unknown[], rangeStart: number, rangeEnd: number, innerGapRatio?: number);
|
|
59
|
+
/** 第 index 个类目的带起始(绝对像素坐标)。 */
|
|
60
|
+
bandStart(index: number): number;
|
|
61
|
+
/** 第 index 个类目的带中心(绝对像素坐标)。 */
|
|
62
|
+
center(index: number): number;
|
|
63
|
+
/** 可用绘图宽度 = 带宽 × (1 - innerGapRatio)。 */
|
|
64
|
+
innerWidth(): number;
|
|
65
|
+
/** 每组(多系列)子柱宽度:按系列数均分可用宽度,并预留 20% 间隙。 */
|
|
66
|
+
groupInnerWidth(groupCount: number): number;
|
|
67
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文字辅助:统一的 font 字符串拼接与文本测量。
|
|
3
|
+
* 所有测量都走 ICanvas2D.measureText,保证跨端一致。
|
|
4
|
+
*/
|
|
5
|
+
import type { ICanvas2D } from './canvas';
|
|
6
|
+
export interface TextStyle {
|
|
7
|
+
fontSize?: number;
|
|
8
|
+
family?: string;
|
|
9
|
+
}
|
|
10
|
+
/** 构造 canvas font 字符串(小程序与 Web 语义一致)。 */
|
|
11
|
+
export declare function toFont(size: number, family?: string): string;
|
|
12
|
+
/** 设置当前文字样式并返回 font 字符串。 */
|
|
13
|
+
export declare function applyFont(ctx: ICanvas2D, size: number, family?: string): string;
|
|
14
|
+
/** 测量文本宽度(自动设置 font)。 */
|
|
15
|
+
export declare function measureWidth(ctx: ICanvas2D, text: string, fontSize: number, family?: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* 截断文本到指定像素宽度(超宽加省略号)。
|
|
18
|
+
* 用于类目轴标签过长时避免溢出绘图区。
|
|
19
|
+
*/
|
|
20
|
+
export declare function truncate(ctx: ICanvas2D, text: string, maxWidth: number, fontSize: number, family?: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图表工厂:按 option.type 分发到具体图表策略类(策略模式入口)。
|
|
3
|
+
*
|
|
4
|
+
* 用法(Web):
|
|
5
|
+
* const chart = createWebChart(canvasEl, { type: 'line', ... });
|
|
6
|
+
* chart.render();
|
|
7
|
+
*
|
|
8
|
+
* 用法(小程序,页面 onReady 后):
|
|
9
|
+
* const node = await getMiniProgramCanvasNode({ selector: '#chart' });
|
|
10
|
+
* const chart = createMiniProgramChart(node, option);
|
|
11
|
+
* chart.render();
|
|
12
|
+
*/
|
|
13
|
+
import type { ChartOption, ChartRenderContext } from './types';
|
|
14
|
+
import type { ChartBase } from './core/chart';
|
|
15
|
+
import type { MiniProgramCanvasNode } from './adapters/miniprogram';
|
|
16
|
+
import type { ResolveCanvasOptions } from './adapters/types';
|
|
17
|
+
/** 按类型创建图表实例(引擎核心入口)。 */
|
|
18
|
+
export declare function createChart<T extends ChartOption>(context: ChartRenderContext, option: T): ChartBase<T>;
|
|
19
|
+
/** Web 便捷入口:从 HTMLCanvasElement 直接创建并渲染。 */
|
|
20
|
+
export declare function createWebChart<T extends ChartOption>(canvas: HTMLCanvasElement, option: T, resolveOptions?: ResolveCanvasOptions): ChartBase<T>;
|
|
21
|
+
/** 小程序便捷入口:从 Canvas 2D 节点直接创建并渲染。 */
|
|
22
|
+
export declare function createMiniProgramChart<T extends ChartOption>(node: MiniProgramCanvasNode, option: T, resolveOptions?: ResolveCanvasOptions): ChartBase<T>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transone-chart:TransOne 跨端图表库。
|
|
3
|
+
*
|
|
4
|
+
* 一份 TypeScript 源码,基于 Canvas 2D 渲染:
|
|
5
|
+
* - Web:HTMLCanvasElement 直接可用
|
|
6
|
+
* - 小程序:微信 / 阿里 / 字节 Canvas 2D 节点
|
|
7
|
+
* - 未来原生 App:实现 ICanvas2D 契约即可接入(见 adapters/native.ts)
|
|
8
|
+
*
|
|
9
|
+
* 一期图表:折线 / 柱状 / 饼图 / 雷达。
|
|
10
|
+
*/
|
|
11
|
+
export * from './types';
|
|
12
|
+
export type { ICanvas2D, IGradient } from './core/canvas';
|
|
13
|
+
export { isCanvas2DLike } from './core/canvas';
|
|
14
|
+
export type { CanvasLineCap, CanvasLineJoin, CanvasTextAlign, CanvasTextBaseline, } from './core/canvas';
|
|
15
|
+
export { LinearScale, CategoryScale, niceTicks } from './core/scale';
|
|
16
|
+
export type { LinearScaleOptions, ScaleResult } from './core/scale';
|
|
17
|
+
export { computeLayout } from './core/layout';
|
|
18
|
+
export type { Box, LayoutInput, LayoutResult, Padding } from './core/layout';
|
|
19
|
+
export { ChartBase } from './core/chart';
|
|
20
|
+
export type { CartesianScales } from './core/chart';
|
|
21
|
+
export { LineChart } from './charts/line';
|
|
22
|
+
export { BarChart } from './charts/bar';
|
|
23
|
+
export { PieChart } from './charts/pie';
|
|
24
|
+
export { RadarChart } from './charts/radar';
|
|
25
|
+
export { createChart, createWebChart, createMiniProgramChart, } from './factory';
|
|
26
|
+
export { resolveWebCanvas, resolveMiniProgramCanvas, getMiniProgramCanvasNode, getMiniProgramGlobal, detectMiniProgramPixelRatio, detectPixelRatio, resolveNativeCanvas, } from './adapters';
|
|
27
|
+
export type { MiniProgramCanvasNode, MiniProgramGlobal, NativeCanvasHost, ResolveCanvasOptions, } from './adapters';
|
|
28
|
+
export { TcChart } from './component';
|
|
29
|
+
export type { TcChartProps } from './component';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var ke=["#1677ff","#00b578","#ff8f1f","#ff3141","#eb2f96","#722ed1","#13c2c2","#faad14","#2f54eb","#a0d911"],V="#323233",Ne="#c8c9cc",ge="#ebedf0",Q="-apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif";function ut(e){return typeof e==="object"&&e!==null&&typeof e.save==="function"&&typeof e.beginPath==="function"&&typeof e.fill==="function"&&typeof e.stroke==="function"&&typeof e.fillText==="function"}function Oe(e,t,n=5){let r=e,o=t;if(!Number.isFinite(r)||!Number.isFinite(o))throw Error("niceTicks: domain must be finite numbers");if(r===o){let u=Math.abs(r)>1?Math.abs(r)*0.1:1;r-=u,o+=u}if(r>o)[r,o]=[o,r];let s=(o-r)/Math.max(1,n),a=pt(s),l=Math.floor(r/a)*a,c=Math.ceil(o/a)*a,p=[];for(let u=l;u<=c+a*0.000000001;u+=a)p.push(ct(u,a));return{min:l,max:c,step:a,ticks:p}}function pt(e){let t=Math.pow(10,Math.floor(Math.log10(e))),n=e/t,r;if(n<=1)r=1;else if(n<=2)r=2;else if(n<=5)r=5;else r=10;return r*t}function ct(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+1);return Number(e.toFixed(n))}class W{min;max;ticks;step;rangeStart;rangeEnd;constructor(e,t,n,r,o={}){let{min:i,max:s,splitCount:a=5}=o,l=i,c=s;if(l===void 0||c===void 0){let p=Oe(e,t,a);l=l??p.min,c=c??p.max,this.ticks=p.ticks,this.step=p.step}else{this.step=(c-l)/Math.max(1,a),this.ticks=[];for(let p=0;p<=a;p+=1)this.ticks.push(l+p*this.step)}this.min=l,this.max=c,this.rangeStart=n,this.rangeEnd=r}scale(e){let t=(e-this.min)/(this.max-this.min);return this.rangeStart+t*(this.rangeEnd-this.rangeStart)}}class J{categories;bandWidth;innerGapRatio;rangeStart;constructor(e,t,n,r=0.35){this.categories=e;this.innerGapRatio=r,this.rangeStart=t;let o=Math.max(1,e.length);this.bandWidth=(n-t)/o}bandStart(e){return this.rangeStart+this.bandWidth*e}center(e){return this.bandStart(e)+this.bandWidth/2}innerWidth(){return this.bandWidth*(1-this.innerGapRatio)}groupInnerWidth(e){return this.innerWidth()/Math.max(1,e)*0.8}}var dt={top:12,right:16,bottom:12,left:16};function ht(e,t){let{legend:n}=e,r=e.legendItems??[],o=n?.fontSize??12,i=n?.itemGap??16,s=n?.markerSize??12;if(n?.position==="right"){let l=0;for(let c of r){let p=s+6+t(c);if(p>l)l=p}return{width:l+12,height:Math.max(r.length*(o+8)+12,0)}}let a=0;for(let l of r)a+=s+6+t(l)+i;if(a>0)a-=i;return{width:a,height:o+12+4}}function ye(e,t){let n={...dt,...e.basePadding},r=n.top,o=n.bottom,i=n.left,s=n.right,a=null;if(e.title?.text){let b=e.title.fontSize??16;a={x:0,y:0,width:e.width,height:b},r+=b+(e.title.padding??16)}let l=null,c=e.legend;if(c&&c.show!==!1&&(e.legendItems?.length??0)>0){let b=ht(e,t),T=c.position??"top";if(T==="top")l={x:0,y:a?a.height:0,width:e.width,height:b.height},r+=b.height;else if(T==="bottom")l={x:0,y:e.height-b.height,width:e.width,height:b.height},o+=b.height;else l={x:e.width-b.width,y:r,width:b.width,height:Math.max(0,e.height-r-o)},s+=b.width}let p=11,u=0,d=0,h=0,m=0,R=e.valueLabels??[],g=e.categoryLabels??[];if(e.horizontal){if(g.length>0){for(let b of g){let T=t(b);if(T>m)m=T}m+=16,i+=m}if(R.length>0)h=p+16,o+=h}else{if(R.length>0){for(let b of R){let T=t(b);if(T>u)u=T}u+=16,i+=u}if(g.length>0)d=p+16,o+=d}let y=Math.max(0,e.width-i-s),C=Math.max(0,e.height-r-o),v={x:i,y:r,width:y,height:C},k=e.horizontal?{x:v.x,y:v.y+v.height,width:y,height:h}:{x:v.x-u,y:r,width:u,height:C},w=e.horizontal?{x:v.x-m,y:r,width:m,height:C}:{x:i,y:v.y+C,width:y,height:d};return{plot:v,valueAxisBox:k,categoryAxisBox:w,titleBox:a,legendBox:l,padding:n}}function mt(e,t=Q){return`${e}px ${t}`}function P(e,t,n=Q){let r=mt(t,n);return e.font=r,r}function z(e,t,n,r=Q){return P(e,n,r),e.measureText(t).width}class be{ctx;constructor(e){this.ctx=e}drawValueAxis(e){let{plot:t,scale:n,labels:r,horizontal:o=!1,labelFontSize:i=11,labelColor:s=V,gridColor:a=ge,gridLineWidth:l=1,gridLineDash:c,showGrid:p=!0}=e,u=n.ticks,{ctx:d}=this;for(let h=0;h<u.length;h+=1){let m=n.scale(u[h]),R=r[h]??String(u[h]);if(p){if(d.save(),d.strokeStyle=a,d.lineWidth=l,c&&c.length>0)d.setLineDash(c);if(d.beginPath(),o)d.moveTo(t.x,m),d.lineTo(t.x+t.width,m);else d.moveTo(t.x,m),d.lineTo(t.x+t.width,m);d.stroke(),d.restore()}if(P(d,i),d.fillStyle=s,d.textBaseline="middle",o)d.textAlign="center",d.fillText(R,m,t.y+t.height+8);else d.textAlign="right",d.fillText(R,t.x-8,m)}}drawCategoryAxis(e){let{plot:t,scale:n,labels:r,horizontal:o=!1,axisColor:i=Ne,labelFontSize:s=11,labelColor:a=V,gridColor:l=ge,gridLineWidth:c=1,showGrid:p=!1}=e,{ctx:u}=this,d=r.length;if(p){u.save(),u.strokeStyle=l,u.lineWidth=c,u.beginPath();for(let h=0;h<d;h+=1){let m=n.center(h);if(o)u.moveTo(t.x,m),u.lineTo(t.x+t.width,m);else u.moveTo(m,t.y),u.lineTo(m,t.y+t.height)}u.stroke(),u.restore()}P(u,s),u.fillStyle=a,u.textBaseline="middle";for(let h=0;h<d;h+=1){let m=n.center(h);if(o)u.textAlign="right",u.fillText(r[h],t.x-8,m);else u.textAlign="center",u.fillText(r[h],m,t.y+t.height+8)}if(u.save(),u.strokeStyle=i,u.lineWidth=1,u.beginPath(),o)u.moveTo(t.x,t.y),u.lineTo(t.x,t.y+t.height);else u.moveTo(t.x,t.y+t.height),u.lineTo(t.x+t.width,t.y+t.height);u.stroke(),u.restore()}}class ve{ctx;constructor(e){this.ctx=e}draw(e){let{box:t,items:n,position:r="top",fontSize:o=12,color:i=V,markerSize:s=12,itemGap:a=16}=e;if(n.length===0)return;let{ctx:l}=this;if(P(l,o),r==="right"){let d=t.y+o/2+4;for(let h of n)this.drawItem(h,t.x,d,o,s,i),d+=o+8;return}let c=0;for(let d of n)c+=s+6+z(l,d.name,o)+a;c-=a;let p=t.x+(t.width-c)/2,u=t.y+t.height/2;for(let d of n)this.drawItem(d,p,u,o,s,i),p+=s+6+z(l,d.name,o)+a}drawItem(e,t,n,r,o,i){let{ctx:s}=this;s.fillStyle=e.color,s.beginPath(),s.rect(t,n-o/2,o,o),s.fill(),s.fillStyle=i,s.textAlign="left",s.textBaseline="middle",s.fillText(e.name,t+o+6,n)}}class A{ctx;option;width;height;dpr;palette;cartesian=null;destroyed=!1;constructor(e,t){this.ctx=e.ctx,this.option=t,this.width=e.width,this.height=e.height,this.dpr=e.dpr,this.palette=e.palette??ke}setOption(e){return this.option={...this.option,...e},this}resize(e,t){return this.width=Math.max(0,e),this.height=Math.max(0,t),this}render(){if(this.destroyed)return this;let{ctx:e,width:t,height:n,dpr:r}=this;e.save(),e.scale(r,r),e.clearRect(0,0,t,n);let o=this.getBackgroundColor();if(o)e.fillStyle=o,e.fillRect(0,0,t,n);let i=this.computeLayout();if(this.drawTitle(i),this.drawLegend(i),this.hasCartesianAxis())this.cartesian=this.buildCartesianScales(i),this.drawCartesianAxis(i);else this.cartesian=null;return this.drawSeries(e,i,this.option),e.restore(),this}destroy(){this.destroyed=!0}isDestroyed(){return this.destroyed}hasCartesianAxis(){return!0}getValueDomain(){return{min:0,max:1}}getCategoryLabels(){return[]}isHorizontal(){return!1}getBackgroundColor(){return this.option.backgroundColor}getTitle(){return this.option.title}getLegend(){let e=this.option.legend;if(e)return e;return this.getLegendItems().length>0?{position:"top"}:void 0}getLegendItems(){return[]}getValueAxis(){return this.option.yAxis}getCategoryAxis(){return this.option.xAxis}computeLayout(){let e=this.buildLayoutInput();return ye(e,(n)=>z(this.ctx,n,11))}buildLayoutInput(){let e=this.isHorizontal(),t=this.hasCartesianAxis();return{width:this.width,height:this.height,title:this.getTitle(),legend:this.getLegend(),legendItems:this.getLegendItems().map((n)=>n.name),valueLabels:t&&!e?this.computeValueLabels():void 0,categoryLabels:t?this.getCategoryLabels():void 0,horizontal:e}}computeValueLabels(){let e=this.getValueDomain(),t=this.getValueAxis();return new W(e.min,e.max,0,1,{min:t?.min,max:t?.max,splitCount:t?.splitCount}).ticks.map((r)=>t?.format?t.format(r):String(r))}drawTitle(e){let t=this.getTitle();if(!t?.text||!e.titleBox)return;let{ctx:n}=this;P(n,t.fontSize??16),n.fillStyle=t.color??"#323233",n.textAlign="center",n.textBaseline="top",n.fillText(t.text,this.width/2,e.titleBox.y)}drawLegend(e){let t=this.getLegend();if(t?.show===!1||!e.legendBox)return;let n=this.getLegendItems();if(n.length===0)return;new ve(this.ctx).draw({box:e.legendBox,items:n,position:t?.position??"top",fontSize:t?.fontSize,color:t?.color,markerSize:t?.markerSize,itemGap:t?.itemGap})}buildCartesianScales(e){let{plot:t}=e,n=this.isHorizontal(),r=this.getValueDomain(),o=this.getCategoryLabels(),i=this.getValueAxis(),s=new W(r.min,r.max,n?t.x:t.y+t.height,n?t.x+t.width:t.y,{min:i?.min,max:i?.max,splitCount:i?.splitCount}),a=new J(o,n?t.y:t.x,n?t.y+t.height:t.x+t.width);return{value:s,category:a}}drawCartesianAxis(e){let t=this.cartesian;if(!t)return;let{ctx:n}=this,{plot:r}=e,o=this.isHorizontal(),i=this.getValueAxis(),s=this.getCategoryAxis(),a=this.getCategoryLabels(),l=new be(n),c=t.value.ticks.map((p)=>i?.format?i.format(p):String(p));l.drawValueAxis({plot:r,scale:t.value,labels:c,horizontal:o,labelFontSize:i?.labelFontSize,labelColor:i?.labelColor,gridColor:i?.gridColor,gridLineWidth:i?.gridLineWidth,gridLineDash:i?.gridLineDash,showGrid:i?.showGrid??!0}),l.drawCategoryAxis({plot:r,scale:t.category,labels:a,horizontal:o,labelFontSize:s?.labelFontSize,labelColor:s?.labelColor,gridColor:s?.gridColor,gridLineWidth:s?.gridLineWidth,showGrid:s?.showGrid??!1})}seriesColor(e,t){return t??this.palette[e%this.palette.length]}}class Z extends A{getValueDomain(){let{series:e,yAxis:t,startFromZero:n=!1}=this.option,r=1/0,o=-1/0;for(let i of e)for(let s of i.data){if(s<r)r=s;if(s>o)o=s}if(!Number.isFinite(r)||!Number.isFinite(o))return{min:0,max:1};if(n&&r>0)r=0;if(t?.min!==void 0)r=Math.min(r,t.min);if(t?.max!==void 0)o=Math.max(o,t.max);return{min:r,max:o}}getCategoryLabels(){return this.option.xAxis.labels}getLegendItems(){return this.option.series.filter((e)=>e.name).map((e,t)=>({name:e.name,color:this.seriesColor(t,e.color)}))}drawSeries(e,t,n){let r=this.cartesian;if(!r)return;let{plot:o}=t,{value:i,category:s}=r,a=n.series.map((l)=>l.data.map((c,p)=>({x:s.center(p),y:i.scale(c)})));n.series.forEach((l,c)=>{let p=a[c];if(p.length===0)return;let u=this.seriesColor(c,l.color),d=l.lineWidth??2;if(l.area)e.save(),e.fillStyle=u,e.globalAlpha=0.15,e.beginPath(),this.tracePath(e,p,l.smooth??!1),e.lineTo(p[p.length-1].x,o.y+o.height),e.lineTo(p[0].x,o.y+o.height),e.closePath(),e.fill(),e.restore();if(e.save(),e.strokeStyle=u,e.lineWidth=d,e.lineJoin="round",e.lineCap="round",e.beginPath(),this.tracePath(e,p,l.smooth??!1),e.stroke(),e.restore(),l.showSymbol!==!1){e.save(),e.fillStyle=u;for(let h of p)e.beginPath(),e.arc(h.x,h.y,Math.max(2.5,d+0.5),0,Math.PI*2),e.fill();e.restore()}})}tracePath(e,t,n){if(t.length===0)return;if(e.moveTo(t[0].x,t[0].y),!n||t.length<3){for(let r=1;r<t.length;r+=1)e.lineTo(t[r].x,t[r].y);return}for(let r=0;r<t.length-1;r+=1){let o=t[Math.max(0,r-1)],i=t[r],s=t[r+1],a=t[Math.min(t.length-1,r+2)],l=i.x+(s.x-o.x)/6,c=i.y+(s.y-o.y)/6,p=s.x-(a.x-i.x)/6,u=s.y-(a.y-i.y)/6;e.bezierCurveTo(l,c,p,u,s.x,s.y)}}}class ee extends A{isHorizontal(){return this.option.horizontal??!1}getValueDomain(){let{series:e,yAxis:t}=this.option,n=0,r=0,o=De(e),i=Math.max(0,...e.map((s)=>s.data.length));for(let s=0;s<i;s+=1)for(let a of o){let l=0,c=0;for(let p of a){let u=p.data[s]??0;if(u>=0)l+=u;else c+=u}if(l>n)n=l;if(c<r)r=c}if(t?.min!==void 0)r=Math.min(r,t.min);if(t?.max!==void 0)n=Math.max(n,t.max);return{min:r,max:n}}getCategoryLabels(){return this.option.xAxis.labels}getLegendItems(){return this.option.series.filter((e)=>e.name).map((e,t)=>({name:e.name,color:this.seriesColor(t,e.color)}))}drawSeries(e,t,n){let r=this.cartesian;if(!r)return;let{value:o,category:i}=r,s=n.horizontal??!1,a=De(n.series),l=n.xAxis.labels.length;for(let c=0;c<l;c+=1){let p=a,u=p.length,d=n.series.map((m)=>m.barWidth).find((m)=>m!==void 0&&m>0),h=this.computeSlot(i,u,d);p.forEach((m,R)=>{let g=h.offset+R*h.size,y=0;m.forEach((C)=>{let v=C.data[c]??0,k=this.seriesColor(n.series.indexOf(C),C.color);if(s){let w=o.scale(0),b=o.scale(y+v),T=Math.min(w,b),F=Math.abs(b-w),fe=i.bandStart(c)+g;this.drawBar(e,{x:T,y:fe,width:F,height:h.size,radius:C.borderRadius??0,color:k,roundSide:v>=0?"right":"left"})}else{let w=o.scale(y),b=o.scale(y+v),T=Math.min(w,b),F=Math.abs(b-w),fe=i.bandStart(c)+g;this.drawBar(e,{x:fe,y:T,width:h.size,height:F,radius:C.borderRadius??0,color:k,roundSide:v>=0?"top":"bottom"})}y+=v})})}}computeSlot(e,t,n){if(n!==void 0)return{offset:(e.innerWidth()-n)/2,size:n};let r=e.innerWidth()/Math.max(1,t)*0.8;return{offset:(e.innerWidth()-r*t)/2,size:r}}drawBar(e,t){if(t.width<=0||t.height<=0)return;e.save(),e.fillStyle=t.color,e.beginPath(),ft(e,t,t.radius,t.roundSide),e.fill(),e.restore()}}function De(e){let t=[],n=new Map;for(let r of e)if(r.stack){let o=n.get(r.stack);if(!o)o=[],n.set(r.stack,o),t.push(o);o.push(r)}else t.push([r]);return t}function ft(e,t,n,r){let{x:o,y:i,width:s,height:a}=t,l=Math.min(n,s/2,a/2);if(l<=0){e.rect(o,i,s,a);return}let c=r==="top"||r==="left",p=r==="top"||r==="right",u=r==="bottom"||r==="left",d=r==="bottom"||r==="right";if(e.moveTo(o+(c?l:0),i),e.lineTo(o+s-(p?l:0),i),p)e.arcTo(o+s,i,o+s,i+l,l);else e.lineTo(o+s,i);if(e.lineTo(o+s,i+a-(d?l:0)),d)e.arcTo(o+s,i+a,o+s-l,i+a,l);else e.lineTo(o+s,i+a);if(e.lineTo(o+(u?l:0),i+a),u)e.arcTo(o,i+a,o,i+a-l,l);else e.lineTo(o,i+a);if(e.lineTo(o,i+(c?l:0)),c)e.arcTo(o,i,o+l,i,l);else e.lineTo(o,i);e.closePath()}var gt=Math.PI*2;class te extends A{hasCartesianAxis(){return!1}getLegendItems(){return this.option.data.map((e,t)=>({name:e.name,color:e.color??this.seriesColor(t)}))}drawSeries(e,t,n){let{plot:r}=t,o=r.x+r.width/2,i=r.y+r.height/2,s=Math.min(r.width,r.height)/2,a=He(n.radius??"60%",s),l=He(n.innerRadius??0,s),c=n.startAngle??-Math.PI/2,p=n.data.filter((h)=>h.value>0),u=p.reduce((h,m)=>h+m.value,0);if(u<=0||a<=0)return;let d=c;p.forEach((h,m)=>{let R=h.value/u*gt,g=h.color??this.seriesColor(m);if(e.save(),e.fillStyle=g,e.beginPath(),l>0)e.arc(o,i,a,d,d+R),e.arc(o,i,l,d+R,d,!0);else e.arc(o,i,a,d,d+R),e.lineTo(o,i);if(e.closePath(),e.fill(),e.strokeStyle="#ffffff",e.lineWidth=1,e.stroke(),e.restore(),n.showLabel!==!1){let y=d+R/2,C=(a+(l>0?l:0))/2*0.85,v=o+Math.cos(y)*C,k=i+Math.sin(y)*C,w=u>0?Math.round(h.value/u*100):0;P(e,n.labelFontSize??10),e.fillStyle=n.labelColor??"#ffffff",e.textAlign="center",e.textBaseline="middle",e.fillText(`${h.name} ${w}%`,v,k)}d+=R})}}function He(e,t){if(typeof e==="number")return Math.max(0,e);let n=/^(\d+(?:\.\d+)?)%$/.exec(e);if(!n)return t;return Number(n[1])/100*t}class ne extends A{hasCartesianAxis(){return!1}getLegendItems(){return this.option.series.filter((e)=>e.name).map((e,t)=>({name:e.name,color:this.seriesColor(t,e.color)}))}drawSeries(e,t,n){let{plot:r}=t,o=r.x+r.width/2,i=r.y+r.height/2,s=n.radius??Math.min(r.width,r.height)/2*0.6,a=n.indicators.length;if(a===0||s<=0)return;let l=n.startAngle??-Math.PI/2,c=yt/a,p=Math.max(1,n.splitCount??5),u=n.gridColor??"#ebedf0",d=n.gridLineWidth??1,h=(g)=>l+g*c,m=(g,y)=>({x:o+Math.cos(g)*y,y:i+Math.sin(g)*y});for(let g=1;g<=p;g+=1){let y=s*g/p;e.save(),e.strokeStyle=u,e.lineWidth=d,e.beginPath();for(let C=0;C<a;C+=1){let v=m(h(C),y);if(C===0)e.moveTo(v.x,v.y);else e.lineTo(v.x,v.y)}e.closePath(),e.stroke(),e.restore()}e.save(),e.strokeStyle=u,e.lineWidth=d,e.beginPath();for(let g=0;g<a;g+=1){let y=m(h(g),s);e.moveTo(o,i),e.lineTo(y.x,y.y)}e.stroke(),e.restore();let R=n.labelFontSize??11;P(e,R),e.fillStyle=n.labelColor??"#323233";for(let g=0;g<a;g+=1){let y=m(h(g),s+12);e.textAlign=Math.abs(y.x-o)<1?"center":y.x>o?"left":"right",e.textBaseline=Math.abs(y.y-i)<1?"middle":y.y>i?"top":"bottom",e.fillText(n.indicators[g].name,y.x,y.y)}n.series.forEach((g,y)=>{let C=this.seriesColor(y,g.color),v=n.indicators.map((k,w)=>{let b=k.max??this.indicatorMax(n,w),T=g.data[w]??0,F=b>0?Math.max(0,Math.min(1,T/b)):0;return m(h(w),s*F)});if(g.area!==!1)e.save(),e.fillStyle=C,e.globalAlpha=0.2,e.beginPath(),this.tracePolygon(e,v),e.closePath(),e.fill(),e.restore();e.save(),e.strokeStyle=C,e.lineWidth=g.lineWidth??2,e.lineJoin="round",e.beginPath(),this.tracePolygon(e,v),e.closePath(),e.stroke(),e.restore()})}indicatorMax(e,t){let n=0;for(let r of e.series){let o=r.data[t]??0;if(o>n)n=o}return n}tracePolygon(e,t){if(t.length===0)return;e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n+=1)e.lineTo(t[n].x,t[n].y)}}var yt=Math.PI*2;function q(){let e=bt();if(typeof e.devicePixelRatio==="number"&&e.devicePixelRatio>0)return e.devicePixelRatio;return 1}function bt(){if(typeof globalThis<"u")return globalThis;return{}}function D(e){let n=vt()[e];return typeof n==="object"&&n!==null?n:null}function re(e){let t=e.platform??oe()??"wx",n=D(t),r=n?.createSelectorQuery;if(typeof r!=="function")return Promise.reject(Error(`getMiniProgramCanvasNode: ${t}.createSelectorQuery is not available`));return new Promise((o,i)=>{let s=r.call(n);if(e.instance&&typeof s.in==="function")s=s.in(e.instance);if(typeof s.select!=="function"){i(Error(`${t}.createSelectorQuery().select is not available`));return}s.select(e.selector).fields({node:!0,size:!0}).exec((a)=>{let c=(Array.isArray(a)?a[0]:void 0)?.node;if(!c||typeof c.getContext!=="function"){i(Error(`getMiniProgramCanvasNode: canvas node not found for "${e.selector}"`));return}o(c)})})}function oe(){if(D("wx"))return"wx";if(D("my"))return"my";if(D("tt"))return"tt";return null}function Ce(e){let t=e??oe()??"wx",n=D(t),r=n?.getSystemInfoSync;if(typeof r==="function")try{let o=r.call(n);if(typeof o.pixelRatio==="number"&&o.pixelRatio>0)return o.pixelRatio}catch{}return q()}function B(e,t={}){let n=e.getContext("2d");if(!n)throw Error("resolveMiniProgramCanvas: 2d context is not available");let r=t.dpr??Ce(),o=t.width??e.width,i=t.height??e.height;return{ctx:n,width:o,height:i,dpr:r,palette:t.palette}}function vt(){if(typeof globalThis<"u")return globalThis;return{}}function j(e,t={}){if(!e)throw Error("resolveWebCanvas: canvas element is required");let n=e.getContext("2d");if(!n)throw Error("resolveWebCanvas: 2d context is not available");let r=t.dpr??q(),o=t.width??(e.clientWidth||e.width),i=t.height??(e.clientHeight||e.height);return e.width=Math.round(o*r),e.height=Math.round(i*r),{ctx:n,width:o,height:i,dpr:r,palette:t.palette}}function U(e,t){switch(t.type){case"line":return new Z(e,t);case"bar":return new ee(e,t);case"pie":return new te(e,t);case"radar":return new ne(e,t);default:throw Error(`createChart: unsupported chart type "${t.type}"`)}}function Ct(e,t,n={}){return U(j(e,n),t)}function Rt(e,t,n={}){return U(B(e,n),t)}function qe(e){throw Error("resolveNativeCanvas is not implemented yet. Native app support (iOS/Android/HarmonyOS) is planned for a future phase; implement ICanvas2D on the host side and fill in this resolver.")}function M(e){if(e===void 0||e===null)return[];return Array.isArray(e)?e:[e]}function Be(e){return typeof e==="object"&&e!==null&&"component"in e}function je(e){return typeof e==="object"&&e!==null&&"tag"in e&&e.tag!=="slot"}function _e(e){return typeof e==="object"&&e!==null&&"tag"in e&&e.tag==="slot"}function Fe(e,t,n,r,o,i){return{tag:e,props:t,children:n,listeners:r,key:o,directions:i}}function xt(e,t={}){return{tag:e,...t}}function f(e){return(t={})=>xt(e,t)}var Tt=f("div"),$n=f("span"),zn=f("p"),Un=f("button"),Gn=f("input"),Kn=f("section"),Xn=f("main"),Yn=f("header"),Qn=f("footer"),Jn=f("nav"),Zn=f("article"),er=f("aside"),tr=f("h1"),nr=f("h2"),rr=f("h3"),or=f("h4"),ir=f("h5"),sr=f("h6"),ar=f("strong"),lr=f("em"),ur=f("small"),pr=f("pre"),cr=f("code"),dr=f("blockquote"),hr=f("ul"),mr=f("ol"),fr=f("li"),gr=f("a"),yr=f("img"),br=f("form"),vr=f("label"),Cr=f("textarea"),Rr=f("select"),xr=f("option"),Tr=f("table"),wr=f("thead"),Er=f("tbody"),Sr=f("tr"),Pr=f("th"),Lr=f("td");var H=Symbol("is_reactive"),E=Symbol("is_readonly"),wt=Symbol("is_ref"),Ve=["push","pop","shift","unshift","splice","sort","reverse"];function S(e,t){return Boolean(Reflect.get(e,t))}function I(e){return e!==null&&typeof e==="object"}class Re{pending=new Set;flushing=!1;flushPromise=null;flushResolve=null;enqueue(e){if(this.pending.has(e))return;if(this.pending.add(e),!this.flushing)queueMicrotask(()=>this.flush())}flush(){if(this.flushing)return;this.flushing=!0;try{while(this.pending.size>0){let e=Array.from(this.pending);this.pending.clear();for(let t of e)if(t.active)t()}}finally{this.flushing=!1;let e=this.flushResolve;this.flushResolve=null,this.flushPromise=null,e?.()}}nextTick(){if(!this.flushing&&this.pending.size===0)return Promise.resolve();if(this.flushPromise)return this.flushPromise;return this.flushPromise=new Promise((e)=>{this.flushResolve=e}),this.flushPromise}}var Et=0,xe=new Re;class L{static instance;activeEffect=null;effectStack=[];targetMap=new WeakMap;reactiveMap=new WeakMap;readonlyMap=new WeakMap;proxyMap=new WeakMap;constructor(){}static getInstance(){if(!L.instance)L.instance=new L;return L.instance}reactive(e){if(!I(e))return console.warn("reactive: target must be an object"),e;if(St(e))return e;if(this.reactiveMap.has(e))return this.reactiveMap.get(e);if(Array.isArray(e))return this.createReactiveArray(e);let t=new Proxy(e,{get:(n,r)=>{if(r===H)return!0;if(r===E)return!1;this.track(n,r);let o=Reflect.get(n,r);if(I(o)&&!S(o,E))return this.reactive(o);return o},set:(n,r,o)=>{if(S(n,E))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(I(o)&&!S(o,H)&&!S(o,E))o=this.reactive(o);let s=Reflect.set(n,r,o);if(i!==o)this.trigger(n,r);return s},deleteProperty:(n,r)=>{if(S(n,E))return console.warn(`Cannot delete property ${String(r)} on readonly object`),!1;let o=r in n,i=Reflect.deleteProperty(n,r);if(o)this.trigger(n,r);return i}});return this.reactiveMap.set(e,t),this.proxyMap.set(t,e),t}toRawValue(e){if(I(e)&&this.proxyMap.has(e))return this.proxyMap.get(e);return e}createReactiveArray(e){if(this.reactiveMap.has(e))return this.reactiveMap.get(e);let t=new Proxy(e,{get:(n,r)=>{if(r===H)return!0;if(r===E)return!1;this.track(n,r);let o=Reflect.get(n,r);if(typeof r==="string"&&(r==="includes"||r==="indexOf"||r==="lastIndexOf")){this.track(n,"length");for(let s=0;s<n.length;s++)this.track(n,String(s));let i=o;return(...s)=>{let a=i.apply(n,s);if(a===!1||a===-1){let l=n.map((p)=>this.toRawValue(p));return l[r].apply(l,s.map((p)=>this.toRawValue(p)))}return a}}if(typeof r==="string"&&Ve.includes(r))return(...i)=>{let a=o.apply(n,i);return this.trigger(n,"length"),this.trigger(n,r),a};if(I(o)&&!S(o,E))return this.reactive(o);return o},set:(n,r,o)=>{if(S(n,E))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(I(o)&&!S(o,H)&&!S(o,E))o=this.reactive(o);let s=Reflect.set(n,r,o);if(i!==o){if(this.trigger(n,r),typeof r==="string"&&!isNaN(Number(r)))this.trigger(n,"length")}return s},deleteProperty:(n,r)=>{if(S(n,E))return console.warn(`Cannot delete property ${String(r)} on readonly object`),!1;let o=r in n,i=Reflect.deleteProperty(n,r);if(o)this.trigger(n,r),this.trigger(n,"length");return i}});return this.reactiveMap.set(e,t),this.proxyMap.set(t,e),t}readonly(e){if(!I(e))return console.warn("readonly: target must be an object"),e;if(S(e,E))return e;if(this.readonlyMap.has(e))return this.readonlyMap.get(e);let t=new Proxy(e,{get:(n,r)=>{if(r===H)return!1;if(r===E)return!0;let o=Reflect.get(n,r);if(I(o))return this.readonly(o);return o},set:()=>(console.warn("Cannot set property on readonly object"),!1),deleteProperty:()=>(console.warn("Cannot delete property on readonly object"),!1)});return this.readonlyMap.set(e,t),t}effect(e,t){let{lazy:n=!1,scheduler:r,throwOnError:o=!1}=t||{},i=()=>{if(!i.active)return e();try{return this.cleanup(i),this.effectStack.push(i),this.activeEffect=i,e()}catch(s){if(o)throw s;console.error("Effect error:",s);return}finally{this.effectStack.pop(),this.activeEffect=this.effectStack[this.effectStack.length-1]??null}};if(i.id=Et++,i.deps=[],i.active=!0,i.scheduler=r,!n)i();return i}runWithEffect(e,t){this.effectStack.push(e),this.activeEffect=e;try{return t()}finally{this.effectStack.pop(),this.activeEffect=this.effectStack[this.effectStack.length-1]??null}}computed(e){let t=!0,n,r={},o=()=>{this.track(r,"value")},i=this.effect(()=>{n=e(),t=!1},{lazy:!0,scheduler:()=>{if(!t)t=!0,this.trigger(r,"value")}});return{get value(){if(t)i();return o(),n}}}cleanup(e){e.deps.forEach((t)=>{t.delete(e)}),e.deps.length=0}track(e,t){if(!this.activeEffect||!this.activeEffect.active)return;let n=this.targetMap.get(e);if(!n)n=new Map,this.targetMap.set(e,n);let r=n.get(t);if(!r)r=new Set,n.set(t,r);if(!r.has(this.activeEffect))r.add(this.activeEffect),this.activeEffect.deps.push(r)}trigger(e,t){let n=this.targetMap.get(e);if(!n)return;let r=n.get(t);if(!r)return;new Set(r).forEach((i)=>{if(i.active)if(i.scheduler)i.scheduler(i);else i()})}stop(e){if(e.active)this.cleanup(e),e.active=!1}}function We(e){return L.getInstance().reactive(e)}function N(e,t){return L.getInstance().effect(e,t)}function O(e){L.getInstance().stop(e)}function St(e){return I(e)&&S(e,H)}function $e(e){let t=e.split(".");if(e.length===0||t.some((n)=>n.length===0||n==="__proto__"||n==="prototype"||n==="constructor"))throw Error(`Invalid model path "${e}"`);return t}function we(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ze(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Pt(e){return typeof e==="string"?e:e.path}function Ee(e,t){let n=e;for(let r of $e(t)){if(!we(n))throw Error(`Invalid model path "${t}"`);if(!ze(n,r)){if(r in n)throw Error(`Invalid model path "${t}"`);return}n=n[r]}return n}function Lt(e,t,n){let r=$e(t),o=e;for(let s of r.slice(0,-1)){if(!ze(o,s)){if(s in o)throw Error(`Invalid model path "${t}"`);o[s]={}}else if(!we(o[s]))throw Error(`Invalid model path "${t}"`);let a=o[s];if(!we(a))throw Error(`Invalid model path "${t}"`);o=a}let i=r[r.length-1];o[i]=n}function Te(e,t){if(typeof e!=="string"&&e.format)return e.format(t);return t===void 0||t===null?"":String(t)}function At(e,t){if(typeof e!=="string"&&e.parse)return e.parse(t);return t}function Mt(e,t,n){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){e.checked=Array.isArray(n)?n.some((r)=>String(r)===e.value):Boolean(n);return}if(e.type==="radio"){e.checked=n===e.value;return}e.value=Te(t,n);return}if(e instanceof HTMLTextAreaElement){e.value=Te(t,n);return}if(e instanceof HTMLSelectElement){if(e.multiple){let r=Array.isArray(n)?new Set(n.map(String)):new Set;for(let o=0;o<e.options.length;o+=1){let i=e.options.item(o);if(!i)continue;i.selected=r.has(i.value)}return}e.value=Te(t,n)}}function It(e,t){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){if(Array.isArray(t)){let n=t.filter((r)=>String(r)!==e.value);return e.checked?[...n,e.value]:n}return e.checked}if(e.type==="radio")return e.checked?e.value:t;return e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement){if(!e.multiple)return e.value;let n=[];for(let r=0;r<e.selectedOptions.length;r+=1){let o=e.selectedOptions.item(r);if(o)n.push(o.value)}return n}return}class Se{bindings=new WeakMap;bind(e,t,n){if(!this.isSupportedControl(e))return;let r=this.bindings.get(e);if(r&&this.sameBinding(r,t))return;this.cleanup(e);let o=Pt(t),i=()=>Mt(e,t,Ee(n,o)),s=e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement&&!["checkbox","radio"].includes(e.type)?"input":"change",a=()=>{let c=Ee(n,o);Lt(n,o,At(t,It(e,c)))};e.addEventListener(s,a);let l=N(i);this.bindings.set(e,{binding:t,path:o,parse:typeof t==="string"?void 0:t.parse,format:typeof t==="string"?void 0:t.format,eventName:s,listener:a,effect:l})}cleanup(e){let t=this.bindings.get(e);if(!t)return;e.removeEventListener(t.eventName,t.listener),O(t.effect),this.bindings.delete(e)}isSupportedControl(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}sameBinding(e,t){if(typeof e.binding==="string"||typeof t==="string")return e.binding===t;return e.path===t.path&&e.parse===t.parse&&e.format===t.format}}var Ue=":root{--tu-rpx:calc(min(100vw, 750px) / 750);}",kt=/(-?\d+(?:\.\d+)?)rpx/g;function ie(e){return String(e).replace(kt,(t,n)=>`calc(${n} * var(--tu-rpx))`)}function se(e){return/^on[A-Z]/.test(e)||/^on[a-z]/.test(e)}function Ge(e){return e.slice(2).toLowerCase()}function Ke(e){let[t,...n]=e.split(".");return{eventName:t,modifiers:new Set(n)}}function Xe(e,t){let n=(r)=>{if(t.has("stop"))r.stopPropagation();if(t.has("prevent"))r.preventDefault();if(t.has("self")&&r.currentTarget!==r.target)return;if(t.has("once"))r.currentTarget.removeEventListener(r.type,n);e(r)};return n}function Ye(e,t,n){let r=t.includes("-")?t:t.replace(/[A-Z]/g,(o)=>`-${o.toLowerCase()}`);e.setProperty(r,ie(n))}class Pe{styleElement=null;styles=new Map;constructor(){}addStyle(e,t){this.styles.set(e,t),this.updateStyles()}removeStyle(e){this.styles.delete(e),this.updateStyles()}clearStyles(){if(this.styles.clear(),this.styleElement)this.styleElement.textContent=""}destroy(){if(this.clearStyles(),this.styleElement)this.styleElement.remove(),this.styleElement=null}ensureStyleElement(){if(!this.styleElement){let e=document.createElement("style");document.head.appendChild(e),this.styleElement=e}return this.styleElement}convertToCSS(e){return Object.entries(e).map(([t,n])=>`${t.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${ie(n)};`).join(`
|
|
2
|
+
`)}updateStyles(){if(this.styles.size===0){if(this.styleElement)this.styleElement.textContent="";return}let e=this.ensureStyleElement(),t=Ue+`
|
|
3
|
+
`;this.styles.forEach((n)=>{if(t+=`${n.selector} {
|
|
4
|
+
${this.convertToCSS(n.properties)}
|
|
5
|
+
}
|
|
6
|
+
`,n.hover)t+=`${n.selector}:hover {
|
|
7
|
+
${this.convertToCSS(n.hover)}
|
|
8
|
+
}
|
|
9
|
+
`;if(n.media)Object.entries(n.media).forEach(([r,o])=>{t+=`@media ${r} {
|
|
10
|
+
${n.selector} {
|
|
11
|
+
${this.convertToCSS(o)}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`})}),e.textContent=t}}class G{state;bindings=[];templateRegex=/{{(.*?)}}/g;constructor(e){this.state=e;if(!e||typeof e!=="object")throw Error("TemplateEngine requires a valid state object")}parseTemplate(e){if(typeof e!=="string")e=String(e);let t=document.createTextNode("");this.templateRegex.lastIndex=0;let n=Array.from(e.matchAll(this.templateRegex));if(n&&n.length>0)this.setupReactiveBindings(t,e,n);else t.textContent=e;return t}setupReactiveBindings(e,t,n){let r=new Set,o=this.evaluateTemplate(t,n,r);e.textContent=o;let i=N(()=>{try{let s=this.evaluateTemplate(t,n,r);if(e.textContent!==s)e.textContent=s}catch(s){console.error("Template update error:",s),e.textContent=`Error: ${s instanceof Error?s.message:"Unknown error"}`}});this.bindings.push({node:e,originalText:t,effect:i})}evaluateTemplate(e,t,n){let r=e;return t.forEach((o)=>{let i=o[1]?.trim();if(i){n.add(i);let s=this.getValueFromState(i),a=s===void 0||s===null?"":String(s);r=r.replace(o[0],a)}}),r}getValueFromState(e){if(!e)return;let t=e.split("."),n=this.state;for(let r of t){if(!n||typeof n!=="object")return;n=n[r]}return n}clearBindings(){this.bindings.forEach((e)=>{O(e.effect)}),this.bindings=[]}getBindingCount(){return this.bindings.length}hasExpressions(e){return this.templateRegex.lastIndex=0,this.templateRegex.test(e)}extractKeys(e){let t=[],n,r=new RegExp(this.templateRegex,"g");while((n=r.exec(e))!==null){let o=n[1]?.trim();if(o)t.push(o)}return t}evaluateTemplateValue(e){this.templateRegex.lastIndex=0;let t=Array.from(e.matchAll(this.templateRegex));if(!t||t.length===0)return e;let n=new Set;return this.evaluateTemplate(e,t,n)}}class K{props;vnode=null;el=null;renderer=new ae;templateEngine;childComponents=new Set;eventListeners={};providers=new Map;updateEffect;appContext=null;parentComponent=null;elementChangeListener=null;styleManager;state;mounted=!1;constructor(e={}){this.props=e;this.styleManager=new Pe,this.state=We(this.initState()??{}),this.templateEngine=new G(this.state),this.initStyles(),this.updateEffect=N(()=>{if(this.mounted)try{this.update()}catch(t){if(!this.dispatchError(t))throw t}},{throwOnError:!0,scheduler:(t)=>{xe.enqueue(t)}})}mount(e){if(!e||!(e instanceof HTMLElement))throw Error("Invalid container element");try{e.appendChild(this.mountToNode())}catch(t){throw console.error("组件渲染错误:",t),t}}mountToNode(){if(this.mounted&&this.el)return this.el;return this.beforeMount(),this.el=L.getInstance().runWithEffect(this.updateEffect,()=>{try{return this.vnode=this.render(),this.renderer.mount(this.vnode,this.createRenderContext())}catch(e){if(this.dispatchError(e))return document.createComment("error-boundary");throw e}}),this.mounted=!0,this.onMounted(),this.el}update(){if(!this.el||!this.vnode)return;this.beforeUpdate();let e=this.vnode,t=this.el;if(this.el=L.getInstance().runWithEffect(this.updateEffect,()=>{let n=this.render(),r=this.renderer.patch(e,n,t,this.createRenderContext());return this.vnode=n,r}),t!==this.el)this.elementChangeListener?.(t,this.el);this.onUpdated(),this.onPropsChange()}unmount(){if(!this.mounted)return;if(this.beforeUnmount(),this.vnode&&this.el)this.renderer.unmount(this.vnode,this.el,this.createRenderContext());if(this.childComponents.clear(),Object.keys(this.eventListeners).forEach((e)=>{this.eventListeners[e].clear(),delete this.eventListeners[e]}),this.providers.clear(),this.parentComponent=null,this.elementChangeListener=null,this.templateEngine.clearBindings(),this.styleManager.destroy(),O(this.updateEffect),this.el?.parentNode)this.el.parentNode.removeChild(this.el);this.el=null,this.vnode=null,this.mounted=!1,this.onUnmounted()}setProps(e){if(this.props={...this.props,...e},this.mounted)xe.enqueue(this.updateEffect)}setState(e){Object.assign(this.state,e)}setAppContext(e){this.appContext=e,this.childComponents.forEach((t)=>{t.setAppContext?.(e)})}setParentComponent(e){this.parentComponent=e}getParentComponent(){return this.parentComponent}setElementChangeListener(e){this.elementChangeListener=e}provide(e,t){this.providers.set(e,t)}inject(e,t){let n=this.resolveInjection(e);return n.found?n.value:t}resolveInjection(e){if(this.providers.has(e))return{found:!0,value:this.providers.get(e)};if(this.parentComponent?.resolveInjection)return this.parentComponent.resolveInjection(e);return this.resolveAppInjection(e)}getElement(){return this.el}beforeMount(){}onMounted(){}beforeUpdate(){}onUpdated(){}onPropsChange(){}beforeUnmount(){}onUnmounted(){}dispatchError(e){let t=this.getParentComponent();while(t){let n=t;if(typeof n.onErrorCaptured==="function"){if(n.onErrorCaptured(e,this)===!1)return!0}t=t.getParentComponent?.()??null}return!1}getContext(){return this.appContext}get router(){return this.getRouterFrom(this.appContext)??this.getRouterFromGlobalApp()}emit(e,...t){this.eventListeners[e]?.forEach((n)=>{n(...t)})}on(e,t){if(!this.eventListeners[e])this.eventListeners[e]=new Set;return this.eventListeners[e].add(t),()=>this.off(e,t)}off(e,t){this.eventListeners[e]?.delete(t)}createRenderContext(){return{appContext:this.appContext,templateEngine:this.templateEngine,renderer:this.renderer,slots:this.collectSlots(),registerChild:(e)=>{this.childComponents.add(e),e.setParentComponent?.(this),e.setAppContext?.(this.appContext)},unregisterChild:(e)=>{this.childComponents.delete(e),e.setParentComponent?.(null)}}}collectSlots(){let e={default:[]};return M(this.props.children).forEach((n)=>{let r=this.getSlotName(n);if(!e[r])e[r]=[];e[r].push(this.normalizeSlotChild(n))}),e}getSlotName(e){if(typeof e==="string")return"default";return"slot"in e&&typeof e.slot==="string"?e.slot:"default"}normalizeSlotChild(e){if(typeof e==="string"||!("slot"in e))return e;let t={...e};return delete t.slot,t}getRouterFrom(e){if(!e||typeof e!=="object"||!("router"in e))return;return e.router}getRouterFromGlobalApp(){let e=globalThis.__APP__;return this.getRouterFrom(e)}resolveAppInjection(e){if(!this.appContext||typeof this.appContext!=="object")return{found:!1,value:void 0};return this.appContext.app?.resolveInjection?.(e)??{found:!1,value:void 0}}}var Nt=null;function Qe(){return Nt}var Je="http://www.w3.org/2000/svg",Ot=new Set(["svg","g","defs","rect","circle","ellipse","line","polyline","polygon","path","text","tspan","textPath","use","symbol","marker","linearGradient","radialGradient","stop","pattern","mask","clipPath","foreignObject"]);class ue{listeners=new WeakMap;effects=new WeakMap;modelBindings=new Se;matches(e){return typeof e==="object"&&e!==null&&je(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=e.tag==="navigator",r=n?document.createElement("a"):Ot.has(e.tag)?document.createElementNS(Je,e.tag):document.createElement(e.tag),o=e.props??{};if(n){let{url:i,openType:s,...a}=o,l=typeof i==="string"?i:"#";r.setAttribute("href",l),r.addEventListener("click",(c)=>{let p=Qe();if(p)c.preventDefault(),p.push(r.getAttribute("href")??"#")}),this.applyProps(r,{},a,t)}else this.applyProps(r,{},o,t);return this.updateListeners(r,{},this.collectListeners(e)),this.mountChildren(r,e,t),this.applyDirections(r,void 0,e.directions,t),r}patch(e,t,n,r){if(e.tag!==t.tag||n.nodeType===Node.COMMENT_NODE){let i=this.mount(t,r);return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}if(!(n instanceof Element))return n;if(t.directions?.if===!1){let i=document.createComment("if");return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}if(t.tag==="navigator"||e.tag==="navigator"){let i=e.props??{},s=t.props??{},a=typeof i.url==="string"?i.url:"",l=typeof s.url==="string"?s.url:"";if(a!==l)n.setAttribute("href",l);let c={...s};delete c.url,delete c.openType,this.applyProps(n,i,c,r)}else this.applyProps(n,e.props??{},t.props??{},r);return this.updateListeners(n,this.collectListeners(e),this.collectListeners(t)),this.updateChildren(n,e,t,r),this.applyDirections(n,e.directions,t.directions,r),n}unmount(e,t,n){if(!(t instanceof Element))return;this.effects.get(t)?.forEach((r)=>O(r)),this.effects.delete(t),this.listeners.get(t)?.forEach(({eventName:r,listener:o})=>{t.removeEventListener(r,o)}),this.listeners.delete(t),this.modelBindings.cleanup(t),this.unmountChildren(t,e,n)}mountChildren(e,t,n){M(t.children).forEach((r)=>{e.appendChild(n.renderer.mount(r,n))})}updateChildren(e,t,n,r){this.updateOrdinaryChildren(e,M(t.children),M(n.children),r)}unmountChildren(e,t,n){M(t.children).forEach((r,o)=>{let i=e.childNodes[o];if(i)n.renderer.unmount(r,i,n)})}applyProps(e,t,n,r){Object.keys(t).forEach((o)=>{if(se(o)||o in n)return;if(o==="className"||o==="class")e.removeAttribute("class");else if(o==="style")e.removeAttribute("style");else if(o==="value"&&typeof e==="object"&&e!==null&&"value"in e)e.value="";else e.removeAttribute(le(o))}),Object.entries(n).forEach(([o,i])=>{if(se(o))return;if(t[o]===i)return;if(o==="className"||o==="class"){if(e.namespaceURI===Je)e.setAttribute("class",String(i??""));else e.className=String(i??"");return}if(o==="value"&&typeof e==="object"&&e!==null&&"value"in e){e.value=String(i??"");return}if(o==="style"&&typeof i==="object"&&i!==null){e.removeAttribute("style");let s=e.style;Object.entries(i).forEach(([a,l])=>{Ye(s,a,l)});return}if(i===!1||i===void 0||i===null){e.removeAttribute(le(o));return}if(i===!0){e.setAttribute(le(o),"");return}if(typeof i==="string"&&r.templateEngine.hasExpressions(i)){this.setupReactiveAttribute(e,o,i,r);return}e.setAttribute(le(o),String(i))})}applyDirections(e,t,n,r){if(n&&"show"in n)e.style.display=n.show?"":"none";else if(t&&"show"in t)e.style.display="";if(!n?.model){this.modelBindings.cleanup(e);return}this.modelBindings.bind(e,n.model,r.templateEngine.state)}updateOrdinaryChildren(e,t,n,r){if(this.assertNoDuplicateKeys(t),this.assertNoDuplicateKeys(n),this.hasOnlyKeyedChildren(t,n)){this.updateKeyedChildren(e,t,n,r);return}let o=Math.min(t.length,n.length);for(let i=0;i<o;i+=1){let s=e.childNodes[i];if(!s){e.appendChild(r.renderer.mount(n[i],r));continue}r.renderer.patch(t[i],n[i],s,r)}for(let i=o;i<n.length;i+=1)e.appendChild(r.renderer.mount(n[i],r));for(let i=t.length-1;i>=n.length;i-=1){let s=e.childNodes[i];if(s){if(r.renderer.unmount(t[i],s,r),s.parentNode===e)e.removeChild(s)}}}updateKeyedChildren(e,t,n,r){let o=t.map((a,l)=>({vnode:a,node:e.childNodes[l],index:l})),i=new Map,s=new Set;o.forEach((a)=>{let l=this.getVNodeKey(a.vnode);if(l!==void 0&&a.node)i.set(l,{vnode:a.vnode,node:a.node,index:a.index})}),n.forEach((a,l)=>{let c=this.getVNodeKey(a),p=c===void 0?void 0:i.get(c),u;if(p)u=r.renderer.patch(p.vnode,a,p.node,r),s.add(p.index);else u=r.renderer.mount(a,r);let d=e.childNodes[l]??null;if(u!==d)e.insertBefore(u,d)}),o.forEach((a)=>{if(!a.node||s.has(a.index))return;if(r.renderer.unmount(a.vnode,a.node,r),a.node.parentNode===e)e.removeChild(a.node)})}hasOnlyKeyedChildren(e,t){return[...e,...t].every((n)=>this.getVNodeKey(n)!==void 0)}assertNoDuplicateKeys(e){let t=new Set;e.forEach((n)=>{let r=this.getVNodeKey(n);if(r===void 0)return;if(t.has(r))throw Error(`Duplicate key "${r}"`);t.add(r)})}getVNodeKey(e){if(typeof e==="string")return;return e.key}collectListeners(e){let t={};return Object.entries(e.props??{}).forEach(([n,r])=>{if(se(n)&&typeof r==="function")t[Ge(n)]=r}),{...t,...e.listeners??{}}}updateListeners(e,t,n){let r=this.listeners.get(e)??new Map,o=new Set(Object.keys(t)),i=new Set(Object.keys(n));o.forEach((s)=>{if(!i.has(s)||t[s]!==n[s]){let a=r.get(s);if(a)e.removeEventListener(a.eventName,a.listener),r.delete(s)}}),i.forEach((s)=>{if(!o.has(s)||t[s]!==n[s]){let{eventName:a,modifiers:l}=Ke(s),c=typeof e.tagName==="string"&&e.tagName.toLowerCase()==="textarea",p=a==="confirm"&&!c?"keydown":a,u=Xe((d)=>{if(p==="keydown"){if(d.key!=="Enter")return}n[s](d)},l);e.addEventListener(p,u),r.set(s,{eventName:p,listener:u})}}),this.listeners.set(e,r)}setupReactiveAttribute(e,t,n,r){let o=N(()=>{e.setAttribute(t,r.templateEngine.evaluateTemplateValue(n))});this.trackEffect(e,o)}trackEffect(e,t){let n=this.effects.get(e)??new Set;n.add(t),this.effects.set(e,n)}}function le(e){if(e.startsWith("data")&&e.length>4)return`data${e.slice(4).replace(/[A-Z]/g,(t)=>`-${t.toLowerCase()}`)}`;if(e==="tabIndex"||e==="colSpan"||e==="htmlFor")return e.toLowerCase();return e}class ae{strategies;constructor(){this.strategies=[new Ze,new et,new tt,new ue]}mount(e,t){return this.findStrategy(e).mount(e,t)}patch(e,t,n,r){let o=this.findStrategy(e),i=this.findStrategy(t);if(o!==i){let s=i.mount(t,r);return n.parentNode?.replaceChild(s,n),o.unmount(e,n,r),s}return o.patch(e,t,n,r)}unmount(e,t,n){this.findStrategy(e).unmount(e,t,n)}findStrategy(e){let t=this.strategies.find((n)=>n.matches(e));if(!t)throw Error("No render strategy found for vnode");return t}}class Ze{matches(e){return typeof e==="string"}mount(e,t){return t.templateEngine.parseTemplate(e)}patch(e,t,n,r){if(e===t)return n;let o=this.mount(t,r);return n.parentNode?.replaceChild(o,n),o}unmount(){}}class et{instances=new WeakMap;instanceNodes=new Map;emitterUnsubscribers=new WeakMap;matches(e){return typeof e==="object"&&e!==null&&Be(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let r=new e.component(this.createProps(e));if(t.appContext&&r.setAppContext)r.setAppContext(t.appContext);this.syncEmitters(r,e.emitters??{}),t.registerChild(r);let o=r.mountToNode();return this.trackInstanceNode(r,o),r.setElementChangeListener?.((i,s)=>{this.trackInstanceNode(r,i),this.trackInstanceNode(r,s)}),o}patch(e,t,n,r){if(n.nodeType===Node.COMMENT_NODE){let s=this.mount(t,r);return n.parentNode?.replaceChild(s,n),s}if(t.directions?.if===!1){let s=document.createComment("if");return n.parentNode?.replaceChild(s,n),this.unmount(e,n,r),s}let o=this.instances.get(n);if(o&&e.component===t.component){this.syncEmitters(o,t.emitters??{}),o.setProps(this.createProps(t));let s=o.getElement()??n;return this.trackInstanceNode(o,s),s}let i=this.mount(t,r);return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}unmount(e,t,n){let r=this.instances.get(t);if(r)this.clearEmitters(r),r.unmount(),this.clearInstanceNodes(r),n.unregisterChild(r)}createProps(e){return{...e.props??{},children:M(e.children)}}syncEmitters(e,t){let n=this.emitterUnsubscribers.get(e)??new Map;n.forEach(({listener:r,unsubscribe:o},i)=>{let s=t[i];if(!s||s!==r)o(),n.delete(i)}),Object.entries(t).forEach(([r,o])=>{if(n.get(r)?.listener===o)return;n.set(r,{listener:o,unsubscribe:e.on(r,o)})}),this.emitterUnsubscribers.set(e,n)}clearEmitters(e){this.emitterUnsubscribers.get(e)?.forEach(({unsubscribe:t})=>{t()}),this.emitterUnsubscribers.delete(e)}trackInstanceNode(e,t){this.instances.set(t,e);let n=this.instanceNodes.get(e)??new Set;n.add(t),this.instanceNodes.set(e,n)}clearInstanceNodes(e){this.instanceNodes.get(e)?.forEach((t)=>{this.instances.delete(t)}),this.instanceNodes.delete(e)}}class tt{renderedChildren=new WeakMap;matches(e){return typeof e==="object"&&e!==null&&_e(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=document.createElement("div");return n.setAttribute("data-slot",e.props.name),this.mountSlotChildren(n,this.resolveChildren(e,t),t),n}patch(e,t,n,r){if(n.nodeType===Node.COMMENT_NODE){let o=this.mount(t,r);return n.parentNode?.replaceChild(o,n),o}if(t.directions?.if===!1){let o=document.createComment("if");return n.parentNode?.replaceChild(o,n),this.unmount(e,n,r),o}if(n instanceof HTMLElement)n.setAttribute("data-slot",t.props.name),this.replaceSlotChildren(n,e,t,r);return n}unmount(e,t,n){if(!(t instanceof HTMLElement))return;this.unmountSlotChildren(t,n),this.renderedChildren.delete(t)}resolveChildren(e,t){return t.slots[e.props.name]??M(e.children)}replaceSlotChildren(e,t,n,r){let o=this.renderedChildren.get(e)??[],i=this.resolveChildren(n,r),s=Math.min(o.length,i.length);for(let a=0;a<s;a+=1){let l=e.childNodes[a];if(!l){e.appendChild(r.renderer.mount(i[a],r));continue}r.renderer.patch(o[a],i[a],l,r)}for(let a=s;a<i.length;a+=1)e.appendChild(r.renderer.mount(i[a],r));for(let a=o.length-1;a>=i.length;a-=1){let l=e.childNodes[a];if(l){if(r.renderer.unmount(o[a],l,r),l.parentNode===e)e.removeChild(l)}}this.renderedChildren.set(e,i)}mountSlotChildren(e,t,n){t.forEach((r)=>{e.appendChild(n.renderer.mount(r,n))}),this.renderedChildren.set(e,t)}unmountSlotChildren(e,t){(this.renderedChildren.get(e)??[]).forEach((r,o)=>{let i=e.childNodes[o];if(i)t.renderer.unmount(r,i,t)})}}class x extends Error{code;config;response;cause;constructor(e){super(e.message);this.name="RequestError",this.code=e.code,this.config=e.config,this.response=e.response,this.cause=e.cause}}var Ht=new Set(["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"]);function pe(e){if(e===void 0)return"GET";let t=e.toUpperCase();if(!Ht.has(t))throw Error(`Unsupported HTTP method: ${e}`);return t}var qt=/^[a-z][a-z\d+.-]*:\/\//i;function Bt(e){return qt.test(e)}function jt(e,t){if(!e||Bt(t))return t;return`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`}function nt(e){if(e instanceof Date)return e.toISOString();if(typeof e==="object")return JSON.stringify(e);return String(e)}function _t(e){if(!e)return"";let t=[];return Object.keys(e).forEach((n)=>{let r=e[n];if(r===void 0||r===null)return;let o=encodeURIComponent(n);if(Array.isArray(r)){r.forEach((i)=>{if(i===void 0||i===null)return;t.push(`${o}=${encodeURIComponent(nt(i))}`)});return}t.push(`${o}=${encodeURIComponent(nt(r))}`)}),t.join("&")}function ce(e,t,n){let r=jt(e,t),o=_t(n);if(!o)return r;let i=r.includes("?")?"&":"?";return`${r}${i}${o}`}function Ft(e){if(e===void 0||e===null)return;return String(e)}function _(...e){let t={},n=new Map;return e.forEach((r)=>{if(!r)return;Object.keys(r).forEach((o)=>{let i=Ft(r[o]);if(i===void 0)return;let s=o.toLowerCase(),a=n.get(s);if(a!==void 0&&a!==o)delete t[a];n.set(s,o),t[o]=i})}),t}function Vt(e,t){return Object.keys(e).some((n)=>n.toLowerCase()===t.toLowerCase())}function rt(e,t,n){if(n==="GET"||n==="HEAD")return;if(e===void 0||e===null)return;if(typeof e==="string")return e;if(typeof FormData<"u"&&e instanceof FormData)return e;if(typeof Blob<"u"&&e instanceof Blob)return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e;if(!Vt(t,"Content-Type"))t["Content-Type"]="application/json";return JSON.stringify(e)}class Le{platform="web";async request(e){let t=pe(e.method),n=ce(e.baseURL,e.url,e.params),r=_(e.headers),o=rt(e.data,r,t),i=new AbortController,s=!1,a=!1,l;if(e.signal)if(e.signal.aborted)a=!0,i.abort();else e.signal.addEventListener("abort",()=>{a=!0,i.abort()},{once:!0});if(typeof e.timeout==="number"&&e.timeout>0)l=setTimeout(()=>{s=!0,i.abort()},e.timeout);let c=e.credentials??(e.withCredentials===!0?"include":"same-origin");try{let p=await fetch(n,{method:t,headers:r,body:o,signal:i.signal,credentials:c}),u={};return p.headers.forEach((h,m)=>{u[m]=h}),{data:await Wt(p,e),statusCode:p.status,statusText:p.statusText,headers:u,config:e}}catch(p){if(s)throw new x({code:"TIMEOUT",message:`Request timeout after ${String(e.timeout)}ms`,config:e,cause:p});if(a||i.signal.aborted)throw new x({code:"ABORTED",message:"Request aborted",config:e,cause:p});throw new x({code:"NETWORK_ERROR",message:p instanceof Error?p.message:String(p),config:e,cause:p})}finally{if(l!==void 0)clearTimeout(l)}}}async function Wt(e,t){if(t.responseType==="arraybuffer")return e.arrayBuffer();let n=await e.text();if(t.dataType==="text"||!n)return n;try{return JSON.parse(n)}catch{return n}}function $t(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof global<"u")return global;return{}}function Me(e){let t=$t()[e];return typeof t==="object"&&t!==null?t:null}function de(){if(Ae("wx"))return"weixin";if(Ae("my"))return"alipay";if(Ae("tt"))return"bytedance";if(typeof fetch==="function")return"web";return"unknown"}function Ae(e){let t=Me(e);return t!==null&&typeof t.request==="function"}var ot={platform:"weixin",globalName:"wx",headerField:"header",statusField:"statusCode",responseHeaderField:"header"},it={platform:"alipay",globalName:"my",headerField:"headers",statusField:"status",responseHeaderField:"headers"},st={platform:"bytedance",globalName:"tt",headerField:"header",statusField:"statusCode",responseHeaderField:"header"};class X{dialect;platform;constructor(e){this.dialect=e;this.platform=e.platform}request(e){let t=Me(this.dialect.globalName);if(!t||typeof t.request!=="function")return Promise.reject(new x({code:"UNSUPPORTED_PLATFORM",message:`${this.dialect.globalName}.request is not available in current environment`,config:e}));let n=t.request;return new Promise((r,o)=>{let i=!1,s=!1,a,l,c=(u)=>{if(s)return;if(s=!0,l!==void 0)clearTimeout(l);u()},p={url:ce(e.baseURL,e.url,e.params),method:e.method??"GET",data:e.data,[this.dialect.headerField]:zt(e.headers),dataType:e.dataType??"json",...e.responseType!==void 0?{responseType:e.responseType}:{},...e.timeout!==void 0&&e.timeout>0?{timeout:e.timeout}:{},success:(u)=>{c(()=>{let d=u[this.dialect.statusField],h=Number(d??u.statusCode??0),m=Ut(u[this.dialect.responseHeaderField]);r({data:u.data,statusCode:h,headers:m,config:e,...Array.isArray(u.cookies)?{cookies:u.cookies}:{},...typeof u.errMsg==="string"?{errMsg:u.errMsg}:{}})})},fail:(u)=>{c(()=>{let d=Gt(u);o(new x({code:i?"TIMEOUT":Kt(d),message:d||"Network request failed",config:e,cause:u}))})}};if(e.timeout!==void 0&&e.timeout>0)l=setTimeout(()=>{i=!0,a?.abort?.()},e.timeout);if(a=n(p)??void 0,e.signal)if(e.signal.aborted)a?.abort?.();else e.signal.addEventListener("abort",()=>{a?.abort?.()},{once:!0})})}}function zt(e){return _(e)}function Ut(e){if(typeof e!=="object"||e===null)return{};let t={};return Object.keys(e).forEach((n)=>{let r=e[n];if(r!==void 0&&r!==null)t[n]=String(r)}),t}function Gt(e){if(typeof e.errMsg==="string")return e.errMsg;if(typeof e.errorMessage==="string")return e.errorMessage;if(typeof e.error==="string")return e.error;return""}function Kt(e){if(!e)return"UNKNOWN";if(/timeout/i.test(e))return"TIMEOUT";if(/abort/i.test(e))return"ABORTED";return"NETWORK_ERROR"}var at={web:new Le,weixin:new X(ot),alipay:new X(it),bytedance:new X(st)};function he(e){let t=at[e];if(!t)throw new x({code:"UNSUPPORTED_PLATFORM",message:`Unsupported request platform: ${String(e)}`,config:{url:""}});return t}async function Ie(e,t,n){if(e.platform!==void 0&&e.platform!=="auto")return he(e.platform);if(t!==void 0)return typeof t==="function"?await t(e):t;if(n!==void 0&&n!=="auto")return he(n);let r=de();if(r==="unknown")throw new x({code:"UNSUPPORTED_PLATFORM",message:"No supported request platform detected (web fetch / wx.request / my.request / tt.request)",config:e});return he(r)}class Y{handlers=[];use(e,t){return this.handlers.push({onFulfilled:e,onRejected:t}),this.handlers.length-1}eject(e){if(this.handlers[e]!==void 0)this.handlers[e]=null}clear(){this.handlers.length=0}forEach(e){this.handlers.forEach((t,n)=>{if(t!==null)e(t,n)})}}class me{interceptors={request:new Y,response:new Y};instanceDefaults;instanceAdapter;instancePlatform;constructor(e={}){let{adapter:t,platform:n,...r}=e;this.instanceAdapter=t,this.instancePlatform=n,this.instanceDefaults={...r}}request(e){let t;try{t=this.mergeConfig(e)}catch(i){return Promise.reject(i)}let n=[];this.interceptors.request.forEach((i)=>{n.push(i.onFulfilled,i.onRejected)}),n.push((i)=>this.dispatch(i),void 0);let r=[];this.interceptors.response.forEach((i)=>{r.push({onFulfilled:i.onFulfilled,onRejected:i.onRejected})});for(let i=r.length-1;i>=0;i-=1){let s=r[i];n.push(s.onFulfilled,s.onRejected)}let o=Promise.resolve(t);while(n.length>0){let i=n.shift(),s=n.shift();o=o.then(i,s)}return o}get(e,t){return this.request({...t,url:e,method:"GET"})}delete(e,t){return this.request({...t,url:e,method:"DELETE"})}head(e,t){return this.request({...t,url:e,method:"HEAD"})}options(e,t){return this.request({...t,url:e,method:"OPTIONS"})}post(e,t,n){return this.request({...n,url:e,method:"POST",data:t})}put(e,t,n){return this.request({...n,url:e,method:"PUT",data:t})}patch(e,t,n){return this.request({...n,url:e,method:"PATCH",data:t})}dispatch(e){return Ie(e,this.instanceAdapter,this.instancePlatform).then((t)=>t.request(e))}mergeConfig(e){if(!e||typeof e!=="object")throw new x({code:"BAD_REQUEST",message:"Request config must be an object",config:e});let t={...this.instanceDefaults,...e,headers:_(this.instanceDefaults.headers,e.headers),params:{...this.instanceDefaults.params,...e.params}};if(typeof t.url!=="string"||t.url.length===0)throw new x({code:"BAD_REQUEST",message:"Request url is required",config:t});try{t.method=pe(t.method)}catch(n){throw new x({code:"BAD_REQUEST",message:n.message,config:t,cause:n})}return t}}var Fi=new me;var Xt="tc-chart-canvas";class lt extends K{chart=null;destroyed=!1;initState(){return{canvasId:Xt}}initStyles(){this.styleManager.addStyle("tc-chart-canvas",{selector:".tc-chart__canvas",properties:{display:"block",height:"100%",width:"100%"}})}render(){return Fe("canvas",{id:this.state.canvasId,className:`tc-chart__canvas${this.props.className?` ${this.props.className}`:""}`,type:"2d"})}onMounted(){this.attachChart()}onUpdated(){if(this.chart&&!this.destroyed)this.chart.setOption(this.props.option).render();else if(!this.chart&&!this.destroyed)this.attachChart()}onUnmounted(){this.destroyed=!0,this.chart?.destroy(),this.chart=null}getChart(){return this.chart}attachChart(){if(this.destroyed)return;this.resolveContext().then((e)=>{if(this.destroyed)return;this.chart=U(e,this.props.option),this.chart.render()}).catch((e)=>{console.error("[TcChart] attach failed:",e)})}getElement(){return super.getElement()}resolveContext(){if(this.props.resolve)return Promise.resolve(this.props.resolve(this.getElement()));let e=oe();if(e){let t=`#${this.state.canvasId}`,n=(r)=>re({platform:e,instance:this,selector:t}).then((o)=>B(o)).catch((o)=>{if(r<=0)throw o;return new Promise((i)=>setTimeout(i,50)).then(()=>n(r-1))});return n(5)}return Promise.resolve(j(this.getElement()))}}export{ee as BarChart,J as CategoryScale,A as ChartBase,Ne as DEFAULT_AXIS_COLOR,Q as DEFAULT_FONT_FAMILY,ge as DEFAULT_GRID_COLOR,ke as DEFAULT_PALETTE,V as DEFAULT_TEXT_COLOR,Z as LineChart,W as LinearScale,te as PieChart,ne as RadarChart,lt as TcChart,ye as computeLayout,U as createChart,Rt as createMiniProgramChart,Ct as createWebChart,Ce as detectMiniProgramPixelRatio,q as detectPixelRatio,re as getMiniProgramCanvasNode,D as getMiniProgramGlobal,ut as isCanvas2DLike,Oe as niceTicks,B as resolveMiniProgramCanvas,qe as resolveNativeCanvas,j as resolveWebCanvas};
|
|
15
|
+
|
|
16
|
+
//# debugId=71613FE96B28FF3C64756E2164756E21
|
|
17
|
+
//# sourceMappingURL=index.js.map
|