pretext-reporter-bao

文本测量和Canvas布局报告工具 - 基于Pretext库,支持多语言文本测量、行布局计算、可视化报告生成

3,891 stars

Best use case

pretext-reporter-bao is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

文本测量和Canvas布局报告工具 - 基于Pretext库,支持多语言文本测量、行布局计算、可视化报告生成

Teams using pretext-reporter-bao should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/pretext-reporter-bao/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/baojun-billion/pretext-reporter-bao/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/pretext-reporter-bao/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How pretext-reporter-bao Compares

Feature / Agentpretext-reporter-baoStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

文本测量和Canvas布局报告工具 - 基于Pretext库,支持多语言文本测量、行布局计算、可视化报告生成

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Pretext Reporter

基于 Pretext 库的文本测量和布局报告工具,支持多语言(包括表情符号、BIDI、CJK)、Canvas 可视化输出。

## 主要功能

### 文本测量
- 快速测量文本高度和宽度
- 支持所有语言(中文、日文、韩文、阿拉伯语、希伯来语等)
- 表情符号和混合文本支持
- 避免DOM布局回流,纯算术计算

### 行布局计算
- 自动换行计算
- 支持固定宽度和行高
- 流式布局支持(可变宽度)
- Shrink Wrap - 找到最窄的适配容器

### 报告生成
- 文本统计(字符数、行数)
- 布局信息(高度、宽度)
- 多种输出格式(Markdown、JSON)
- Canvas 可视化(PNG 导出)

## 使用场景

1. **虚拟列表高度计算** - 精确计算项目容器高度
2. **动态UI布局** - 预先测量文本防止布局偏移
3. **Canvas/SVG渲染** - 文本渲染到Canvas或SVG
4. **开发时验证** - 测试按钮标签是否溢出
5. **文本编辑器** - 实现自定义文本编辑和测量

## 核心优势

- **性能优异** - prepare 约19ms,layout 约0.09ms(500个文本批次)
- **无DOM依赖** - 纯算术计算,不触发浏览器回流
- **精确测量** - 使用浏览器字体引擎作为基准
- **全面支持** - 所有语言、表情符号、混合BIDI

## API 对接

使用 Pretext 的核心 API:

```typescript
// 用例1:简单测量
import { prepare, layout } from '@chenglou/pretext'

const prepared = prepare('你好世界 🚀', '16px Inter')
const { height, lineCount } = layout(prepared, 320, 24)

// 用例2:行级控制
import { prepareWithSegments, layoutWithLines } from '@chenglou/pretext'

const prepared = prepareWithSegments('你好世界 🚀', '16px Inter')
const { lines } = layoutWithLines(prepared, 320, 24)

// 用例3:流式布局
import { layoutNextLine } from '@chenglou/pretext'

let cursor = { segmentIndex: 0, graphemeIndex: 0 }
let y = 0

while (true) {
  const width = y < image.bottom ? 300 : 320
  const line = layoutNextLine(prepared, cursor, width)
  if (line === null) break
  
  ctx.fillText(line.text, 0, y)
  cursor = line.end
  y += 24
}
```

## 使用方法

### 基础用法

```typescript
// 测量文本
import { measureText } from '@claw/skills/pretext-reporter-bao'

const result = await measureText('你好世界 🚀', {
  font: '16px Inter',
  maxWidth: 320,
  lineHeight: 24
})

console.log(result)
// {
//   text: '你好世界 🚀',
//   characterCount: 5,
//   lineCount: 1,
//   height: 24,
//   lines: [{ text: '你好世界 🚀', width: 87.5 }]
// }
```

### 生成Canvas报告

```typescript
// 生成Canvas可视化
import { generateCanvasReport } from '@claw/skills/pretext-reporter-bao'

const canvas = await generateCanvasReport('你好世界 🚀', {
  font: '16px Inter',
  maxWidth: 320,
  lineHeight: 24,
  backgroundColor: '#ffffff',
  textColor: '#000000'
})

// 保存或使用Canvas
const png = canvas.toDataURL('image/png')
```

### 流式布局

```typescript
// 流式布局(支持图片环绕等)
import { createFlowLayout } from '@claw/skills/pretext-reporter-bao'

const layout = createFlowLayout('你好世界 🚀', {
  font: '16px Inter',
  lineHeight: 24
})

// 逐行布局
let line
while ((line = layout.nextLine(320)) !== null) {
  console.log(line.text, line.width)
}
```

## 配置选项

| 选项 | 类型 | 默认值 | 说明 |
|------|------|---------|------|
| `font` | string | `'16px Inter'` | 字体(与CSS font属性格式一致) |
| `maxWidth` | number | `320` | 最大宽度(像素) |
| `lineHeight` | number | `24` | 行高(像素) |
| `whiteSpace` | `'normal' \| 'pre-wrap'` | `'normal'` | 空白处理方式 |
| `backgroundColor` | string | `'#ffffff'` | Canvas背景色 |
| `textColor` | string | `'#000000'` | Canvas文字颜色 |

## 输出格式

### Markdown报告

```markdown
# 文本测量报告

## 基本信息
- 文本:你好世界 🚀
- 字符数:5
- 行数:1
- 字体:16px Inter

## 布局信息
- 最大宽度:320px
- 计算高度:24px
- 行高:24px

## 行详情
| 行号 | 文本 | 宽度 |
|------|------|------|
| 1 | 你好世界 🚀 | 87.5px |
```

### JSON报告

```json
{
  "text": "你好世界 🚀",
  "font": "16px Inter",
  "config": {
    "maxWidth": 320,
    "lineHeight": 24,
    "whiteSpace": "normal"
  },
  "stats": {
    "characterCount": 5,
    "lineCount": 1,
    "height": 24
  },
  "lines": [
    {
      "index": 0,
      "text": "你好世界 🚀",
      "width": 87.5,
      "start": { "segmentIndex": 0, "graphemeIndex": 0 },
      "end": { "segmentIndex": 0, "graphemeIndex": 5 }
    }
  ]
}
```

## 性能基准

| 操作 | 时间 | 说明 |
|------|------|------|
| `prepare()` | ~19ms | 500个文本批次(一次性分析) |
| `layout()` | ~0.09ms | 热路径(纯算术计算) |
| `layoutWithLines()` | ~0.12ms | 包含行信息返回 |

## 依赖

- `@chenglou/pretext` - 核心文本测量库(需手动安装)

## 安装说明

**前置步骤:Pretext 还未发布到 npm,需要手动安装:**

```bash
# 方式1:从 GitHub 克隆
git clone https://github.com/chenglou/pretext.git
cd pretext
npm install
npm link  # 全局链接

# 方式2:在项目中本地引用
# 将 pretext 目录复制到 node_modules/@chenglou/pretext
```

**然后安装本 Skill:**
```bash
cd skills/pretext-reporter-bao
npm install
```

## 参考资料

- Pretext GitHub: https://github.com/chenglou/pretext
- Pretext Demo: https://chenglou.me/pretext
- Pretext Docs: https://github.com/chenglou/pretext#readme

Related Skills

biz-reporter

3891
from openclaw/skills

Automated business intelligence reports pulling data from Google Analytics GA4, Google Search Console, Stripe revenue, social media metrics (Twitter/X, LinkedIn, Instagram), HubSpot CRM, and Airtable into formatted daily KPI snapshots, weekly marketing reports, and monthly business reviews with trend detection and anomaly alerts. Use this skill for: business reports, KPI dashboard, weekly metrics, marketing report, revenue summary, traffic report, analytics summary, performance report, "how are we doing", "show me our metrics", "what are our numbers", MRR tracking, conversion rate analysis, SEO performance report, social media analytics, sales pipeline report, automated reporting via cron, data visualization, business intelligence, growth metrics, churn analysis, or any request to combine data from multiple business tools into a single formatted report. Also works for ad-hoc questions like "how did our launch go" or "compare this month to last month". Delivers via Slack, email, Notion, or Markdown file.

microbiome-diversity-reporter

3891
from openclaw/skills

Interpret Alpha and Beta diversity metrics from 16S rRNA sequencing results.

Binance Event Contract Reporter

3891
from openclaw/skills

## 1. Scenario Definition

performance-reporter

3891
from openclaw/skills

SEO and GEO performance reporter: generate dashboards with rankings, organic traffic, backlink metrics, and AI visibility trends for stakeholder reporting. Part of a 20-skill SEO & GEO workflow suite. SEO报告/数据看板/网站流量分析/SEO数据/流量报告

---

3891
from openclaw/skills

name: article-factory-wechat

Content & Documentation

humanizer

3891
from openclaw/skills

Remove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.

Content & Documentation

find-skills

3891
from openclaw/skills

Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.

General Utilities

tavily-search

3891
from openclaw/skills

Use Tavily API for real-time web search and content extraction. Use when: user needs real-time web search results, research, or current information from the web. Requires Tavily API key.

Data & Research

baidu-search

3891
from openclaw/skills

Search the web using Baidu AI Search Engine (BDSE). Use for live information, documentation, or research topics.

Data & Research

agent-autonomy-kit

3891
from openclaw/skills

Stop waiting for prompts. Keep working.

Workflow & Productivity

Meeting Prep

3891
from openclaw/skills

Never walk into a meeting unprepared again. Your agent researches all attendees before calendar events—pulling LinkedIn profiles, recent company news, mutual connections, and conversation starters. Generates a briefing doc with talking points, icebreakers, and context so you show up informed and confident. Triggered automatically before meetings or on-demand. Configure research depth, advance timing, and output format. Walking into meetings blind is amateur hour—missed connections, generic small talk, zero leverage. Use when setting up meeting intelligence, researching specific attendees, generating pre-meeting briefs, or automating your prep workflow.

Workflow & Productivity

self-improvement

3891
from openclaw/skills

Captures learnings, errors, and corrections to enable continuous improvement. Use when: (1) A command or operation fails unexpectedly, (2) User corrects Claude ('No, that's wrong...', 'Actually...'), (3) User requests a capability that doesn't exist, (4) An external API or tool fails, (5) Claude realizes its knowledge is outdated or incorrect, (6) A better approach is discovered for a recurring task. Also review learnings before major tasks.

Agent Intelligence & Learning