将 H5 游戏项目打包成 Apple iBook 支持的 .wdgt(Widget)格式。适用于:已有 H5 游戏项目(包含 index.html、CSS、JS 等文件),需要打包成 iBook Author 可用的 Widget 压缩包(.wdgt.zip)时使用。自动完成目录结构规范化、资源路径修正、Info.plist 生成、缩略图生成、最终 zip 打包全流程。
本技能可将任意 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,确认:
bash
路径修正规则:
将修正了资源引用路径的 index.html 写入 your-game.wdgt/index.html。
必须包含的 meta 标签(用于全屏适配):
html
xml
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
使用 Python3 + Pillow 生成渐变缩略图(若 Pillow 未安装,先执行 pip3 install Pillow):
python
from PIL import Image, ImageDraw
def makethumb(size, path, gamename):
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(gamename)*7, cy - 10), gamename, 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 绘制更精美的预览图。
bash
cd /path/to/output/parent
zip -r your-game.wdgt.zip your-game.wdgt/
注意: 必须先 cd 到 wdgt 文件夹的父目录,再执行 zip,确保压缩包内顶层是 your-game.wdgt/ 文件夹。
bash
期望看到:
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
...
使用 displaydownloadlinks 工具为用户提供 zip 文件的下载链接。
打包完成后,请告知用户以下使用步骤:
⚠️ 注意:iBook Author 已于 2020 年停止更新,仅支持旧版 macOS。若用户使用新版系统,建议使用 Apple Pages 或第三方工具替代。
在 style.css 中加入响应式断点,确保游戏在不同设备上自适应:
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 加入:
css
html, body {
padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
}
| 问题 | 原因 | 解决方案 |
|------|------|
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 ibook-widget-packer-1776119761 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 ibook-widget-packer-1776119761 技能
skillhub install ibook-widget-packer-1776119761
文件大小: 12.19 KB | 发布时间: 2026-4-17 15:03