← Back to Skills Marketplace
onedream1985

iBook Widget Packer

by onedream1985 · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ Security Clean
146
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install ibook-widget-packer
Description
将 H5 游戏项目打包成 Apple iBook 支持的 .wdgt(Widget)格式。适用于:已有 H5 游戏项目(包含 index.html、CSS、JS 等文件),需要打包成 iBook Author 可用的 Widget 压缩包(.wdgt.zip)时使用。自动完成目录结构规范化、资源路径修正、Info...
README (SKILL.md)

iBook Widget Packer Skill

概述

本 Skill 将任意 H5 游戏项目打包成符合 Apple iBook Author Widget 规范的 .wdgt 格式压缩包,可直接导入 iBook Author 使用。

Widget 包体规范

Apple iBook Widget(.wdgt)本质是一个特定结构的文件夹,在 macOS 上显示为 bundle 包。标准结构如下:

your-game.wdgt/
├── index.html          ← 主入口文件(必须)
├── Info.plist          ← Widget 配置文件(必须)
├── Default.png         ← 缩略图 1024×768(必须)
├── [email protected]      ← 高清缩略图 2048×1536(必须)
└── peresources/        ← 资源文件夹(推荐命名,存放 CSS/JS/图片等)
    ├── style.css
    ├── game.js
    └── ...(其他资源)

关键约束:

  • index.html 必须在根目录
  • Info.plist 必须在根目录,且包含 MainHTML 字段指向 index.html
  • 所有资源路径使用相对路径(如 peresources/style.css
  • 压缩时文件夹本身要在 zip 顶层(即 zip 内容为 your-game.wdgt/...

执行步骤

收到用户的打包请求后,按以下步骤执行:

Step 1:确认源项目路径和输出名称

  • 询问或从上下文确认:
    • 源项目目录(包含 index.html 的目录)
    • Widget 名称(将作为 .wdgt 文件夹名,建议英文+连字符,如 my-game
    • 游戏显示名称(中文可以,用于 Info.plist 的 CFBundleDisplayName)
    • 版本号(默认 1.0
    • 默认尺寸(默认 1024×768,适合 iPad 横屏)

Step 2:分析源项目结构

读取源项目的 index.html,确认:

  • 引用了哪些 CSS/JS 文件及其路径
  • 是否已经有 peresources 子目录,还是所有文件平铺在根目录
  • 特殊资源(图片、音频、字体等)的位置

Step 3:创建 Widget 目录结构

# 创建 wdgt 文件夹
WDGT_DIR="/path/to/output/your-game.wdgt"
mkdir -p "$WDGT_DIR/peresources"

# 将 CSS、JS 等资源文件复制到 peresources/
cp source/style.css source/game.js source/*.js "$WDGT_DIR/peresources/"

路径修正规则:

  • 若源 index.html 中引用路径为 style.css(平铺),则复制到 peresources/ 后,index.html 中需改为 peresources/style.css
  • 若源 index.html 中已经是 peresources/style.css,则路径无需修改,直接复制资源文件到对应位置

Step 4:生成 index.html(根目录版本)

将修正了资源引用路径的 index.html 写入 your-game.wdgt/index.html

必须包含的 meta 标签(用于全屏适配):

\x3Cmeta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
\x3Cmeta name="apple-mobile-web-app-capable" content="yes" />
\x3Cmeta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

Step 5:生成 Info.plist

\x3C?xml version="1.0" encoding="UTF-8"?>
\x3C!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
\x3Cplist version="1.0">
\x3Cdict>
  \x3Ckey>CFBundleDisplayName\x3C/key>
  \x3Cstring>【游戏中文名】\x3C/string>
  \x3Ckey>CFBundleIdentifier\x3C/key>
  \x3Cstring>com.【英文名小写】.widget\x3C/string>
  \x3Ckey>CFBundleName\x3C/key>
  \x3Cstring>【英文名驼峰】\x3C/string>
  \x3Ckey>CFBundleShortVersionString\x3C/key>
  \x3Cstring>【版本号,如 1.0】\x3C/string>
  \x3Ckey>CFBundleVersion\x3C/key>
  \x3Cstring>【版本号,如 1.0】\x3C/string>
  \x3Ckey>MainHTML\x3C/key>
  \x3Cstring>index.html\x3C/string>
  \x3Ckey>AllowNetworkAccess\x3C/key>
  \x3Cfalse/>
  \x3Ckey>Width\x3C/key>
  \x3Cinteger>1024\x3C/integer>
  \x3Ckey>Height\x3C/key>
  \x3Cinteger>768\x3C/integer>
\x3C/dict>
\x3C/plist>

Step 6:生成缩略图

使用 Python3 + Pillow 生成渐变缩略图(若 Pillow 未安装,先执行 pip3 install Pillow):

from PIL import Image, ImageDraw

def make_thumb(size, path, game_name):
    w, h = size
    img = Image.new('RGB', (w, h))
    draw = ImageDraw.Draw(img)
    # 渐变背景(紫色系)
    for i in range(h):
        r = int(102 + (150-102)*i/h)
        g = int(51 + (75-51)*i/h)
        b = int(153 + (210-153)*i/h)
        draw.line([(0,i),(w,i)], fill=(r,g,b))
    # 中心文字
    cx, cy = w//2, h//2
    draw.text((cx - len(game_name)*7, cy - 10), game_name, fill='white')
    img.save(path)

make_thumb((1024, 768),  'your-game.wdgt/Default.png', '游戏名称')
make_thumb((2048, 1536), 'your-game.wdgt/[email protected]', '游戏名称')

如果需要更好的缩略图效果,可以请用户提供截图,或用 PIL 绘制更精美的预览图。

Step 7:打包成 zip

cd /path/to/output/parent
zip -r your-game.wdgt.zip your-game.wdgt/

注意: 必须先 cd 到 wdgt 文件夹的父目录,再执行 zip,确保压缩包内顶层是 your-game.wdgt/ 文件夹。

Step 8:验证包体结构

# 查看压缩包内容,确认结构正确
unzip -l your-game.wdgt.zip | head -20

期望看到:

Archive:  your-game.wdgt.zip
  your-game.wdgt/
  your-game.wdgt/index.html
  your-game.wdgt/Info.plist
  your-game.wdgt/Default.png
  your-game.wdgt/[email protected]
  your-game.wdgt/peresources/style.css
  your-game.wdgt/peresources/game.js
  ...

Step 9:提供下载链接

使用 display_download_links 工具为用户提供 zip 文件的下载链接。


iBook 使用方式(告知用户)

打包完成后,请告知用户以下使用步骤:

  1. 下载 your-game.wdgt.zip 到本地 Mac
  2. 解压得到 your-game.wdgt 文件夹
  3. 重命名确认:确保文件夹后缀为 .wdgt(macOS 会将其识别为 Widget bundle)
  4. 导入 iBook Author:打开 iBook Author → 插入菜单 → Widget → HTML → 拖入 .wdgt 文件
  5. 预览:在 iBook Author 中点击预览,或导出到 iPad 的 iBooks App 查看

⚠️ 注意:iBook Author 已于 2020 年停止更新,仅支持旧版 macOS。若用户使用新版系统,建议使用 Apple Pages 或第三方工具替代。


屏幕适配最佳实践

style.css 中加入响应式断点,确保游戏在不同设备上自适应:

/* iPad Pro 横屏 (≥1000pt) */
@media screen and (min-width: 1000px) { ... }

/* iPad Pro 竖屏 (768-999pt) */
@media screen and (min-width: 768px) and (max-width: 999px) { ... }

/* iPhone 竖屏 (≤480pt) */
@media screen and (max-width: 480px) { ... }

/* 横屏低高度兼容 */
@media screen and (max-height: 500px) { ... }

同时在 html, body 加入:

html, body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

常见问题排查

问题 原因 解决方案
Widget 在 iBook 中显示空白 index.html 路径错误或资源404 检查 index.html 在 wdgt 根目录,资源路径使用相对路径
缩略图不显示 Default.png 尺寸不对 确保 320×240 和 640×480
游戏布局错乱 缺少 viewport meta 添加 viewport-fit=cover meta 标签
音频无法播放 浏览器自动播放限制 监听用户首次交互事件后再播放音频
zip 结构错误 打包路径问题 确保从 wdgt 父目录执行 zip 命令

输出清单

每次打包完成,向用户说明:

  • ✅ Widget 名称和版本
  • ✅ 包体文件列表(find your-game.wdgt -type f | sort
  • ✅ zip 文件大小
  • ✅ 下载链接
  • ✅ iBook 导入使用步骤
Usage Guidance
This skill appears to do exactly what it claims: create a .wdgt folder, fix resource paths, generate Info.plist and thumbnails, then zip the result. It does not contact external endpoints or ask for secrets. Precautions: (1) The script will remove an existing <widget>.wdgt directory (shutil.rmtree) before creating the new one — avoid using important system paths as the output and back up any existing data. (2) The widget_name parameter is used verbatim in paths; avoid passing names containing ../ or unexpected characters to prevent writing outside the intended output directory. (3) Review the generated index.html/Info.plist if you need to ensure no unintended modifications, and run the script in a safe/test directory first. (4) Verify that the 'display_download_links' helper mentioned in the README/SKILL.md is the legitimate platform utility before using it to publish files.
Capability Analysis
Type: OpenClaw Skill Name: ibook-widget-packer Version: 0.1.0 The skill bundle is a legitimate utility designed to package H5 games into Apple iBook .wdgt format. The Python script (pack_widget.py) and instructions (SKILL.md) perform standard file system operations, directory management, and thumbnail generation using the Pillow library. No evidence of data exfiltration, malicious execution, or harmful prompt injection was found.
Capability Assessment
Purpose & Capability
Name/description match the provided SKILL.md, README, and pack_widget.py. The script and instructions only perform filesystem operations (copy, modify HTML, generate Info.plist, create thumbnails, zip) required to produce a .wdgt package.
Instruction Scope
Instructions are narrowly scoped to packaging tasks (analyze index.html, copy resources, fix paths, create thumbnails, zip). The SKILL.md references a platform utility 'display_download_links' to provide download links — confirm this is the expected platform helper. The tool also suggests running 'pip3 install Pillow' when needed (normal).
Install Mechanism
This is an instruction-only skill with an included helper script; there is no install spec and no external downloads. The only package the script may ask to install is Pillow (via pip) to generate thumbnails, which is proportionate.
Credentials
The skill requests no environment variables, credentials, or config paths. The script operates on user-supplied filesystem paths only, which is consistent with its purpose.
Persistence & Privilege
Skill is not forced-always, does not request persistent or cross-skill privileges, and allows normal model invocation. No modifications to other skills or global agent settings are present.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install ibook-widget-packer
  3. After installation, invoke the skill by name or use /ibook-widget-packer
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.1.0
Initial release of ibook-widget-packer: - Packages H5 game projects into Apple iBook-compatible .wdgt (Widget) zip format. - Automates directory structuring, resource path fixing, Info.plist and thumbnail image generation, and final zip packaging. - Supports customizable Widget name, display name, version, and dimensions. - Provides step-by-step process instructions, usage guidance, and troubleshooting tips. - Requires Linux/macOS, Python3 (for thumbnails), and zip command line tool.
Metadata
Slug ibook-widget-packer
Version 0.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is iBook Widget Packer?

将 H5 游戏项目打包成 Apple iBook 支持的 .wdgt(Widget)格式。适用于:已有 H5 游戏项目(包含 index.html、CSS、JS 等文件),需要打包成 iBook Author 可用的 Widget 压缩包(.wdgt.zip)时使用。自动完成目录结构规范化、资源路径修正、Info... It is an AI Agent Skill for Claude Code / OpenClaw, with 146 downloads so far.

How do I install iBook Widget Packer?

Run "/install ibook-widget-packer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is iBook Widget Packer free?

Yes, iBook Widget Packer is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does iBook Widget Packer support?

iBook Widget Packer is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created iBook Widget Packer?

It is built and maintained by onedream1985 (@onedream1985); the current version is v0.1.0.

💬 Comments