weifuwu 0.90.0 → 0.90.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * weifuwu/components — WordCloud
3
+ *
4
+ * 词云——权重→字号映射 · **中心同心环发散布局**(SVG textLength 定宽——
5
+ * 渲染宽度精确 = 估算宽——同输入同输出——SSR≡SPA 零差异 + 词矩形零重叠)
6
+ * 零依赖自绘 SVG(Chart 同族)。canvas 测宽/Canvas 绘制判负(服务端无 canvas——
7
+ * 见 git log plan/2026-09-wordcloud-组件.md 判负记录——中心排列消费证据推翻
8
+ * 行式装箱——同心环以 SVG 确定性实现:碰撞=矩形相交(纯函数))。
9
+ *
10
+ * 布局契约(纯函数——确定性——测试可断言):
11
+ * - 权重线性映射 [minFontSize, maxFontSize](全等权重 → 全 maxFontSize)
12
+ * - 降序放置——最大词从中心(环 0)开始——**同心环扫描**:环宽 = 当前词高
13
+ * (邻环相接不重叠——环形约束)——环内候选点间距 = max(词宽, 环宽)(奇数环
14
+ * 错相偏 π/n——无隙漏)——首个无碰撞点放置
15
+ * - viewBox = 全部词包围盒(自适应——零裁剪——height 为显示高)
16
+ * - 词矩形(含 padding 间距)两两不相交(环碰撞保证 + textLength 强制实际宽)
17
+ */
18
+ import type { Component } from '../../vdom/index.ts';
19
+ export interface WordCloudData {
20
+ /** 词文本 */
21
+ word: string;
22
+ /** 权重(≥0——0 不渲染) */
23
+ weight: number;
24
+ /** 覆盖色板(不传按 colors 取模) */
25
+ color?: string;
26
+ }
27
+ export interface WordCloudProps {
28
+ words: WordCloudData[];
29
+ /** 显示高度(px——SVG 等比缩放——默认=布局包围盒高) */
30
+ height?: number;
31
+ /** 最大字号(px)——默认 32 */
32
+ maxFontSize?: number;
33
+ /** 最小字号(px)——默认 12 */
34
+ minFontSize?: number;
35
+ /** 词四周间距(px)——默认 4 */
36
+ padding?: number;
37
+ /** 色板(默认 token 色阶——逐词取模) */
38
+ colors?: string[];
39
+ /** 点击词回调(提供后词可交互:hover 高亮 + 键盘 Enter/Space 可达) */
40
+ onWordClick?: (word: string, weight: number) => void;
41
+ className?: string;
42
+ }
43
+ /** 估算词渲染宽(textLength 将强制实际=此值) */
44
+ export declare function estimateWordWidth(word: string, size: number): number;
45
+ export interface PlacedWord {
46
+ word: string;
47
+ weight: number;
48
+ /** 中心 x(text-anchor: middle) */
49
+ x: number;
50
+ /** 基线 y */
51
+ y: number;
52
+ size: number;
53
+ /** textLength(= 实际渲染字宽——不含 padding) */
54
+ textLength: number;
55
+ /** 词级颜色(WordCloudData.color——透传——未传由色板兜底) */
56
+ color?: string;
57
+ /** 布局矩形(含 padding——零重叠断言单位) */
58
+ rect: {
59
+ l: number;
60
+ t: number;
61
+ r: number;
62
+ b: number;
63
+ };
64
+ }
65
+ /** 布局输出(viewBox = 包围盒——由内容决定——零裁剪) */
66
+ export interface WordCloudLayout {
67
+ placed: PlacedWord[];
68
+ /** 布局坐标系宽(= 包围盒宽) */
69
+ width: number;
70
+ /** 布局坐标系高(= 包围盒高) */
71
+ height: number;
72
+ }
73
+ /** 中心同心环布局(纯函数——确定性——同输入同输出——零重叠) */
74
+ export declare function layoutWords(words: WordCloudData[], opts: {
75
+ maxFontSize: number;
76
+ minFontSize: number;
77
+ padding: number;
78
+ }): WordCloudLayout;
79
+ export declare const WordCloud: Component<WordCloudProps>;
@@ -285,3 +285,5 @@ export { VideoPlayer } from './VideoPlayer/VideoPlayer.ts';
285
285
  export type { VideoPlayerProps } from './VideoPlayer/VideoPlayer.ts';
286
286
  export { Math } from './Math/Math.ts';
287
287
  export type { MathProps } from './Math/Math.ts';
288
+ export { WordCloud } from './WordCloud/WordCloud.ts';
289
+ export type { WordCloudProps, WordCloudData } from './WordCloud/WordCloud.ts';