Install
openclaw skills install @onedream1985/ibook-widget-packer将 H5 游戏项目打包成 Apple iBook 支持的 .wdgt(Widget)格式。适用于:已有 H5 游戏项目(包含 index.html、CSS、JS 等文件),需要打包成 iBook Author 可用的 Widget 压缩包(.wdgt.zip)时使用。自动完成目录结构规范化、资源路径修正、Info.plist 生成、缩略图生成、最终 zip 打包全流程。
openclaw skills install @onedream1985/ibook-widget-packer本 Skill 将任意 H5 游戏项目打包成符合 Apple iBook Author Widget 规范的 .wdgt 格式压缩包,可直接导入 iBook Author 使用。
Apple iBook Widget(.wdgt)本质是一个特定结构的文件夹,在 macOS 上显示为 bundle 包。标准结构如下:
your-game.wdgt/
├── index.html ← 主入口文件(必须)
├── Info.plist ← Widget 配置文件(必须)
├── Default.png ← 缩略图 1024×768(必须)
├── Default@2x.png ← 高清缩略图 2048×1536(必须)
└── peresources/ ← 资源文件夹(推荐命名,存放 CSS/JS/图片等)
├── style.css
├── game.js
└── ...(其他资源)
关键约束:
index.html 必须在根目录Info.plist 必须在根目录,且包含 MainHTML 字段指向 index.htmlperesources/style.css)your-game.wdgt/...)收到用户的打包请求后,按以下步骤执行:
my-game)1.0)读取源项目的 index.html,确认:
peresources 子目录,还是所有文件平铺在根目录# 创建 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.cssindex.html 中已经是 peresources/style.css,则路径无需修改,直接复制资源文件到对应位置将修正了资源引用路径的 index.html 写入 your-game.wdgt/index.html。
必须包含的 meta 标签(用于全屏适配):
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>【游戏中文名】</string>
<key>CFBundleIdentifier</key>
<string>com.【英文名小写】.widget</string>
<key>CFBundleName</key>
<string>【英文名驼峰】</string>
<key>CFBundleShortVersionString</key>
<string>【版本号,如 1.0】</string>
<key>CFBundleVersion</key>
<string>【版本号,如 1.0】</string>
<key>MainHTML</key>
<string>index.html</string>
<key>AllowNetworkAccess</key>
<false/>
<key>Width</key>
<integer>1024</integer>
<key>Height</key>
<integer>768</integer>
</dict>
</plist>
使用 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/Default@2x.png', '游戏名称')
如果需要更好的缩略图效果,可以请用户提供截图,或用 PIL 绘制更精美的预览图。
cd /path/to/output/parent
zip -r your-game.wdgt.zip your-game.wdgt/
注意: 必须先 cd 到 wdgt 文件夹的父目录,再执行 zip,确保压缩包内顶层是 your-game.wdgt/ 文件夹。
# 查看压缩包内容,确认结构正确
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/Default@2x.png
your-game.wdgt/peresources/style.css
your-game.wdgt/peresources/game.js
...
使用 display_download_links 工具为用户提供 zip 文件的下载链接。
打包完成后,请告知用户以下使用步骤:
your-game.wdgt.zip 到本地 Macyour-game.wdgt 文件夹.wdgt(macOS 会将其识别为 Widget bundle).wdgt 文件⚠️ 注意: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 命令 |
每次打包完成,向用户说明:
find your-game.wdgt -type f | sort)