@karinjs/plugin-puppeteer
Version:
karin的 puppeteer截图、渲染插件
307 lines (304 loc) • 12.3 kB
JavaScript
import { package_default, saveConfig, getConfig } from './chunk-PIY2AHNK.js';
import { components } from 'node-karin';
var webConfig = {
info: {
id: package_default.name,
name: "\u6E32\u67D3\u5668\u63D2\u4EF6",
version: package_default.version,
description: package_default.description,
author: [
{
name: "sj817",
home: "https://sj817.com",
avatar: "https://github.com/sj817.png"
}
],
icon: {
name: "search",
size: 24,
color: "#0078d4"
// 浅蓝色
}
},
/** 动态渲染的组件 */
components: () => {
const config = getConfig();
return [
components.switch.create("downloadEnable", {
label: "\u542F\u7528\u6D4F\u89C8\u5668\u4E0B\u8F7D",
description: "\u662F\u5426\u542F\u7528\u6D4F\u89C8\u5668\u81EA\u52A8\u4E0B\u8F7D\u529F\u80FD",
defaultSelected: config.download?.enable !== false,
color: "success"
}),
components.radio.group("downloadBrowser", {
label: "\u4E0B\u8F7D\u7684\u6D4F\u89C8\u5668",
orientation: "horizontal",
description: "\u6CA1\u6709\u6D4F\u89C8\u5668\u65F6\uFF0C\u4E0B\u8F7D\u7684\u6D4F\u89C8\u5668\u7C7B\u578B\uFF0Clinux\u63A8\u8350 chrome-headless-shell",
defaultValue: config.download?.browser || "chrome",
radio: [
components.radio.create("chrome", {
label: "chrome",
value: "chrome"
}),
components.radio.create("chromium", {
label: "chromium",
value: "chromium"
}),
components.radio.create("chrome-headless-shell", {
label: "chrome-headless-shell",
value: "chrome-headless-shell"
})
]
}),
components.input.string("downloadVersion", {
label: "\u4E0B\u8F7D\u6D4F\u89C8\u5668\u7248\u672C",
description: "\u652F\u6301\uFF1Alatest\u3001stable\u3001beta\u3001dev\u3001canary \u6216\u7279\u5B9A\u7248\u672C\u53F7",
defaultValue: config.download?.version || "stable",
isRequired: false,
className: "inline-block p-2"
}),
components.input.string("downloadDir", {
label: "\u4E0B\u8F7D\u76EE\u5F55",
description: "\u6D4F\u89C8\u5668\u4E0B\u8F7D\u4FDD\u5B58\u76EE\u5F55\uFF0C\u4E3A\u7A7A\u5219\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84",
defaultValue: config.download?.dir || "",
isRequired: false,
className: "inline-block p-2"
}),
components.input.string("downloadBaseUrl", {
label: "\u81EA\u5B9A\u4E49\u4E0B\u8F7D\u6E90",
description: "\u81EA\u5B9A\u4E49\u4E0B\u8F7D\u6E90URL\uFF0C\u4E0D\u5EFA\u8BAE\u8BBE\u7F6E",
defaultValue: config.download?.baseUrl || "",
isRequired: false,
className: "inline-block p-2"
}),
components.divider.create("divider0"),
components.radio.group("protocol", {
label: "protocol",
orientation: "horizontal",
description: "\u8FDE\u63A5\u5230\u6D4F\u89C8\u5668\u7684\u534F\u8BAE",
defaultValue: config.protocol || "cdp",
radio: [
components.radio.create("cdp", {
label: "cdp",
value: "cdp",
description: "chrome devtools protocol\uFF0C\u6027\u80FD\u4E00\u822C\uFF0C\u4F46\u662F\u7A33\u5B9A"
}),
components.radio.create("webDriverBiDi", {
label: "webDriverBiDi",
value: "webDriverBiDi",
description: "webDriverBiDi\uFF0C\u6027\u80FD\u66F4\u597D\uFF0C\u901F\u5EA6\u66F4\u5FEB\uFF0C\u76EE\u524D\u5904\u4E8E\u5F00\u53D1\u4E2D\uFF0C\u8C28\u614E\u4F7F\u7528"
})
]
}),
components.divider.create("divider1"),
components.radio.group("headless", {
label: "\u65E0\u5934\u6A21\u5F0F",
orientation: "horizontal",
description: "\u65E0\u5934\u6A21\u5F0F\u914D\u7F6E\uFF0C\u6700\u65B0\u7248chrome\u652F\u6301\u6240\u6709\u9009\u9879",
defaultValue: config.headless || "new",
radio: [
components.radio.create("new", {
label: "new",
value: "new",
description: "\u4F7F\u7528\u65B0\u7684\u65E0\u5934\u6A21\u5F0F\uFF08\u63A8\u8350\uFF09"
}),
components.radio.create("shell", {
label: "shell",
value: "shell",
description: "\u4F7F\u7528\u4F20\u7EDF\u65E0\u5934\u6A21\u5F0F\uFF08\u4EC5chrome-headless-shell\uFF09"
}),
components.radio.create("false", {
label: "false",
value: "false",
description: "\u4EE5\u6709\u5934\u6A21\u5F0F\u542F\u52A8\u6D4F\u89C8\u5668"
})
]
}),
components.divider.create("divider3"),
components.switch.create("debug", {
label: "debug\u6A21\u5F0F",
description: "\u662F\u5426\u5F00\u542Fdebug\u6A21\u5F0F\uFF0Cdebug\u6A21\u5F0F\u4E0B\uFF0C\u6D4F\u89C8\u5668\u5C06\u524D\u53F0\u8FD0\u884C\uFF0C\u5E76\u4E14\u6253\u5F00\u9875\u9762\u540E\u4E0D\u4F1A\u5173\u95ED\uFF0C\u4EC5\u5728windows\u4E0B\u6709\u6548",
defaultSelected: config.debug,
color: "success"
}),
// findBrowser
components.switch.create("findBrowser", {
label: "\u81EA\u52A8\u67E5\u627E\u6D4F\u89C8\u5668",
description: "\u542F\u7528\u540E\u4F1A\u4F7F\u7528 @snapka/browser-finder \u67E5\u627E\u7CFB\u7EDF\u6D4F\u89C8\u5668\u3001puppeteer\u3001playwright\u4E0B\u8F7D\u7684\u6D4F\u89C8\u5668",
defaultSelected: config.findBrowser !== false,
color: "success"
}),
// pipe
components.switch.create("pipe", {
label: "\u7BA1\u9053\u6A21\u5F0F",
description: "\u662F\u5426\u5F00\u542F\u7BA1\u9053\u6A21\u5F0F\uFF0C\u5F00\u542F\u540E\uFF0C\u6D4F\u89C8\u5668\u5C06\u4F7F\u7528\u7BA1\u9053\u6A21\u5F0F\u8FD0\u884C",
defaultSelected: config.pipe,
color: "success"
}),
components.divider.create("divider2"),
// slowMo
components.input.number("slowMo", {
label: "\u6162\u52A8\u4F5C\u5EF6\u8FDF",
description: "\u64CD\u4F5C\u6162\u52A8\u4F5C\u5EF6\u8FDF\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C\u7528\u4E8E\u8C03\u8BD5",
defaultValue: (config.slowMo || 0) + "",
className: "inline-block p-2",
rules: [
{
min: 0,
max: 1e4,
error: "\u6162\u52A8\u4F5C\u5EF6\u8FDF\u5FC5\u987B\u57280-10000\u4E4B\u95F4"
}
]
}),
// maxOpenPages
components.input.number("maxOpenPages", {
label: "\u6700\u5927\u6807\u7B7E\u9875",
description: "\u6700\u591A\u540C\u65F6\u6253\u5F00\u7684\u6807\u7B7E\u9875\u6570\u91CF\uFF0C\u8D85\u51FA\u540E\u5C06\u4F1A\u81EA\u52A8\u6392\u961F",
defaultValue: (config.maxOpenPages || 10) + "",
className: "inline-block p-2",
rules: [
{
min: 1,
max: 100,
error: "\u6700\u5927\u6807\u7B7E\u9875\u6570\u91CF\u5FC5\u987B\u57281-100\u4E4B\u95F4"
}
]
}),
// pageMode
components.radio.group("pageMode", {
label: "\u9875\u9762\u6A21\u5F0F",
orientation: "horizontal",
description: "\u9875\u9762\u7BA1\u7406\u6A21\u5F0F\uFF1A\u590D\u7528\u6A21\u5F0F\u6027\u80FD\u66F4\u597D\uFF0C\u4E00\u6B21\u6027\u6A21\u5F0F\u9694\u79BB\u6027\u66F4\u5F3A",
defaultValue: config.pageMode || "reuse",
radio: [
components.radio.create("reuse", {
label: "reuse",
value: "reuse",
description: "\u590D\u7528\u6A21\u5F0F\uFF08\u63A8\u8350\uFF09"
}),
components.radio.create("disposable", {
label: "disposable",
value: "disposable",
description: "\u4E00\u6B21\u6027\u6A21\u5F0F"
})
]
}),
// pageIdleTimeout
components.input.number("pageIdleTimeout", {
label: "\u9875\u9762\u7A7A\u95F2\u8D85\u65F6",
description: "\u9875\u9762\u5728\u6C60\u4E2D\u7A7A\u95F2\u8D85\u8FC7\u6B64\u65F6\u95F4\u540E\u4F1A\u88AB\u81EA\u52A8\u9500\u6BC1\uFF08\u6BEB\u79D2\uFF09\uFF0C\u8BBE\u7F6E\u4E3A0\u8868\u793A\u6C38\u4E0D\u8D85\u65F6",
defaultValue: (config.pageIdleTimeout || 6e4) + "",
className: "inline-block p-2",
rules: [
{
min: 0,
max: 999999999,
error: "\u9875\u9762\u7A7A\u95F2\u8D85\u65F6\u5FC5\u987B\u5927\u4E8E\u7B49\u4E8E0"
}
]
}),
// executablePath
components.input.string("executablePath", {
label: "\u6D4F\u89C8\u5668\u53EF\u6267\u884C\u8DEF\u5F84",
description: "\u6D4F\u89C8\u5668\u53EF\u6267\u884C\u8DEF\u5F84\uFF0C\u5982\u679C\u4E3A\u7A7A\uFF0C\u5C06\u4F1A\u81EA\u52A8\u4E0B\u8F7D\u6D4F\u89C8\u5668",
defaultValue: config.executablePath,
isRequired: false,
className: "inline-block p-2"
}),
// userDataDir
components.input.string("userDataDir", {
label: "\u7528\u6237\u6570\u636E\u76EE\u5F55",
description: "\u7528\u6237\u6570\u636E\u76EE\u5F55\uFF0C\u5982\u679C\u4E3A\u7A7A\uFF0C\u5C06\u4F1A\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84",
defaultValue: config.userDataDir,
isRequired: false,
className: "inline-block p-2"
}),
// defaultViewport width
components.input.number("viewportWidth", {
label: "\u9ED8\u8BA4\u89C6\u7A97\u5BBD\u5EA6",
description: "\u9ED8\u8BA4\u89C6\u7A97\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF09",
defaultValue: (config.defaultViewport?.width || 800) + "",
className: "inline-block p-2",
rules: [
{
min: 1,
max: 1e4,
error: "\u89C6\u7A97\u5BBD\u5EA6\u5FC5\u987B\u57281-10000\u4E4B\u95F4"
}
]
}),
// defaultViewport height
components.input.number("viewportHeight", {
label: "\u9ED8\u8BA4\u89C6\u7A97\u9AD8\u5EA6",
description: "\u9ED8\u8BA4\u89C6\u7A97\u9AD8\u5EA6\uFF08\u50CF\u7D20\uFF09",
defaultValue: (config.defaultViewport?.height || 600) + "",
className: "inline-block p-2",
rules: [
{
min: 1,
max: 1e4,
error: "\u89C6\u7A97\u9AD8\u5EA6\u5FC5\u987B\u57281-10000\u4E4B\u95F4"
}
]
}),
// 分隔线
components.divider.create("divider4"),
// args
components.input.group("args", {
label: "\u542F\u52A8\u53C2\u6570",
description: "\u542F\u52A8\u53C2\u6570\uFF0C\u4E0D\u5141\u8BB8\u51FA\u73B0\u7A7A\u503C\uFF0C\u65E0\u7279\u6B8A\u9700\u6C42\u4E0D\u5EFA\u8BAE\u6539\u52A8",
template: components.input.string("args", {
label: "\u542F\u52A8\u53C2\u6570"
}),
data: config.args || []
})
];
},
/** 前端点击保存之后调用的方法 */
save: (config) => {
if (!config.download) {
config.download = {};
}
if (config.downloadEnable !== void 0) {
config.download.enable = config.downloadEnable;
delete config.downloadEnable;
}
if (config.downloadBrowser) {
config.download.browser = config.downloadBrowser;
delete config.downloadBrowser;
}
if (config.downloadVersion) {
config.download.version = config.downloadVersion;
delete config.downloadVersion;
}
if (config.downloadDir) {
config.download.dir = config.downloadDir;
delete config.downloadDir;
}
if (config.downloadBaseUrl) {
config.download.baseUrl = config.downloadBaseUrl;
delete config.downloadBaseUrl;
}
if (config.viewportWidth !== void 0 || config.viewportHeight !== void 0) {
config.defaultViewport = {
width: Number(config.viewportWidth || 800),
height: Number(config.viewportHeight || 600)
};
delete config.viewportWidth;
delete config.viewportHeight;
}
config = {
...config,
maxOpenPages: Number(config.maxOpenPages),
pageIdleTimeout: Number(config.pageIdleTimeout),
slowMo: Number(config.slowMo || 0)
};
saveConfig(config);
return {
success: true,
message: "\u597D\u4E86\u54E6 \u03C6(>\u03C9<*)"
};
}
};
var web_config_default = webConfig;
export { web_config_default as default };