- hub: FastAPI backend (MCP server, ADB LAN controller, bridge, storage) - hub/web: Vue 3 admin console (device manager, screen mirror, chat workbench) - android: Kotlin shell app with WebView stage, OTA, telemetry, keep-alive - protocol: architecture, MCP schema, and WebSocket protocol specs
282 lines
14 KiB
JavaScript
282 lines
14 KiB
JavaScript
import fs from 'fs'
|
||
import path from 'path'
|
||
import zlib from 'zlib'
|
||
import { fileURLToPath } from 'url'
|
||
import * as esbuild from 'esbuild'
|
||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||
const nm = path.resolve(__dirname, 'node_modules')
|
||
const outDir = path.resolve(__dirname, '../app/src/main/assets/pulsewall/libs')
|
||
fs.mkdirSync(outDir, { recursive: true })
|
||
|
||
function reportSize(filename) {
|
||
const full = path.join(outDir, filename)
|
||
const buf = fs.readFileSync(full)
|
||
const gz = zlib.gzipSync(buf, { level: 9 })
|
||
return {
|
||
file: filename,
|
||
raw_kb: Number((buf.length / 1024).toFixed(1)),
|
||
gzip_kb: Number((gz.length / 1024).toFixed(1))
|
||
}
|
||
}
|
||
|
||
function copyDist(srcRel, dstName) {
|
||
const src = path.join(nm, srcRel)
|
||
fs.copyFileSync(src, path.join(outDir, dstName))
|
||
return reportSize(dstName)
|
||
}
|
||
|
||
async function bundleEntry(code, outName, globalName) {
|
||
await esbuild.build({
|
||
stdin: {
|
||
contents: code,
|
||
resolveDir: __dirname,
|
||
loader: 'js'
|
||
},
|
||
bundle: true,
|
||
minify: true,
|
||
format: 'iife',
|
||
globalName,
|
||
target: ['chrome83', 'es2020'],
|
||
outfile: path.join(outDir, outName)
|
||
})
|
||
return reportSize(outName)
|
||
}
|
||
|
||
function generateTailwindLiteCss() {
|
||
const css = `
|
||
/* PulseWall Prebuilt Tailwind-Compatible Utility Subset (Android 11 WebView safe, zero JS runtime) */
|
||
.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.block{display:block}.inline-block{display:inline-block}.hidden{display:none}
|
||
.flex-col{flex-direction:column}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.flex-1{flex:1 1 0%}.shrink-0{flex-shrink:0}
|
||
.items-center{align-items:center}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-stretch{align-items:stretch}
|
||
.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.justify-start{justify-content:flex-start}
|
||
.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}
|
||
.col-span-2{grid-column:span 2/span 2}.col-span-full{grid-column:1/-1}
|
||
.gap-1{gap:4px}.gap-2{gap:8px}.gap-3{gap:12px}.gap-4{gap:16px}.gap-5{gap:20px}.gap-6{gap:24px}
|
||
.space-y-2>*+*{margin-top:8px}.space-y-3>*+*{margin-top:12px}.space-y-4>*+*{margin-top:16px}
|
||
.p-1{padding:4px}.p-2{padding:8px}.p-3{padding:12px}.p-4{padding:16px}.p-5{padding:20px}.p-6{padding:24px}
|
||
.px-2{padding-left:8px;padding-right:8px}.px-3{padding-left:12px;padding-right:12px}.px-4{padding-left:16px;padding-right:16px}.px-5{padding-left:20px;padding-right:20px}
|
||
.py-1{padding-top:4px;padding-bottom:4px}.py-2{padding-top:8px;padding-bottom:8px}.py-3{padding-top:12px;padding-bottom:12px}.py-4{padding-top:16px;padding-bottom:16px}
|
||
.m-0{margin:0}.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mx-auto{margin-left:auto;margin-right:auto}
|
||
.w-full{width:100%}.h-full{height:100%}.min-h-screen{min-height:100vh}.max-w-full{max-width:100%}.aspect-video{aspect-ratio:16/9}
|
||
.relative{position:relative}.absolute{position:absolute}.inset-0{top:0;right:0;bottom:0;left:0}.overflow-hidden{overflow:hidden}.overflow-auto{overflow:auto}
|
||
.rounded{border-radius:6px}.rounded-lg{border-radius:10px}.rounded-xl{border-radius:14px}.rounded-2xl{border-radius:18px}.rounded-full{border-radius:9999px}
|
||
.border{border:1px solid rgba(148,163,184,0.22)}.border-slate-700{border-color:#334155}.border-slate-800{border-color:#1e293b}.border-cyan-500{border-color:#06b6d4}.border-teal-400{border-color:#2dd4bf}.border-amber-500{border-color:#f59e0b}.border-red-500{border-color:#ef4444}
|
||
.text-xs{font-size:12px;line-height:16px}.text-sm{font-size:14px;line-height:20px}.text-base{font-size:16px;line-height:24px}.text-lg{font-size:18px;line-height:26px}.text-xl{font-size:20px;line-height:28px}.text-2xl{font-size:24px;line-height:32px}.text-3xl{font-size:30px;line-height:36px}.text-4xl{font-size:36px;line-height:40px}
|
||
.font-medium{font-weight:500}.font-semibold{font-weight:600}.font-bold{font-weight:700}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
||
.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||
.text-white{color:#fff}.text-slate-200{color:#e2e8f0}.text-slate-300{color:#cbd5e1}.text-slate-400{color:#94a3b8}.text-slate-500{color:#64748b}
|
||
.text-teal-400{color:#2dd4bf}.text-cyan-400{color:#22d3ee}.text-sky-400{color:#38bdf8}.text-emerald-400{color:#34d399}.text-amber-400{color:#fbbf24}.text-red-400{color:#f87171}.text-rose-400{color:#fb7185}
|
||
.bg-slate-950{background-color:#020617}.bg-slate-900{background-color:#0f172a}.bg-slate-800{background-color:#1e293b}.bg-slate-700{background-color:#334155}
|
||
.bg-teal-500{background-color:#14b8a6}.bg-cyan-500{background-color:#06b6d4}.bg-sky-500{background-color:#0ea5e9}.bg-emerald-500{background-color:#10b981}.bg-amber-500{background-color:#f59e0b}.bg-red-600{background-color:#dc2626}
|
||
.bg-slate-900\\/80{background-color:rgba(15,23,42,0.8)}.bg-slate-800\\/80{background-color:rgba(30,41,59,0.8)}
|
||
.shadow-lg{box-shadow:0 10px 24px rgba(0,0,0,0.35)}.opacity-60{opacity:0.6}.opacity-80{opacity:0.8}
|
||
.cursor-pointer{cursor:pointer}.transition{transition:all 0.15s ease}
|
||
@keyframes pw-pulse{0%,100%{opacity:1}50%{opacity:.45}}.animate-pulse{animation:pw-pulse 1.8s cubic-bezier(.4,0,.6,1) infinite}
|
||
@keyframes pw-spin{to{transform:rotate(360deg)}}.animate-spin{animation:pw-spin 1s linear infinite}
|
||
@media(min-width:640px){.sm\\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}}
|
||
@media(min-width:900px){.md\\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.md\\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}}
|
||
`.trim()
|
||
fs.writeFileSync(path.join(outDir, 'tailwind-lite.min.css'), css, 'utf8')
|
||
return reportSize('tailwind-lite.min.css')
|
||
}
|
||
|
||
function generateUltraLightIcons() {
|
||
// <2KB gzip pure SVG/CSS icon runtime (EagleICON / OpenTiny-style ultra-light offline icons)
|
||
const js = `(function(g){
|
||
var P={
|
||
cpu:"M9 2v2M15 2v2M9 20v2M15 20v2M2 9h2M2 15h2M20 9h2M20 15h2M6 6h12v12H6zM9 9h6v6H9z",
|
||
thermometer:"M14 14.76V3.5a2.5 2.5 0 0 0-5 0v11.26a4.5 4.5 0 1 0 5 0z",
|
||
battery:"M2 7h16v10H2zM22 11v2",
|
||
wifi:"M5 12.55a11 11 0 0 1 14.08 0M1.42 9a16 16 0 0 1 21.16 0M8.53 16.11a6 6 0 0 1 6.95 0M12 20h.01",
|
||
bell:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9M13.73 21a2 2 0 0 1-3.46 0",
|
||
alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0zM12 9v4M12 17h.01",
|
||
check:"M20 6L9 17l-5-5",
|
||
x:"M18 6L6 18M6 6l12 12",
|
||
play:"M5 3l14 9-14 9V3z",
|
||
pause:"M6 4h4v16H6zM14 4h4v16h-4z",
|
||
tv:"M2 7h20v13H2zM17 2l-5 5-5-5",
|
||
server:"M2 2h20v8H2zM2 14h20v8H2zM6 6h.01M6 18h.01",
|
||
activity:"M22 12h-4l-3 9L9 3l-3 9H2",
|
||
clock:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 6v6l4 2",
|
||
settings:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4",
|
||
refresh:"M23 4v6h-6M1 20v-6h6M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15",
|
||
home:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
|
||
sun:"M12 17a5 5 0 1 0 0-10 5 5 0 0 0 0 10zM12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42",
|
||
cloud:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",
|
||
database:"M12 2C6.5 2 2 3.8 2 6v12c0 2.2 4.5 4 10 4s10-1.8 10-4V6c0-2.2-4.5-4-10-4zM2 12c0 2.2 4.5 4 10 4s10-1.8 10-4",
|
||
terminal:"M4 17l6-6-6-6M12 19h8",
|
||
volume:"M11 5L6 9H2v6h4l5 4V5zM19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07",
|
||
zap:"M13 2L3 14h9l-1 8 10-12h-9l1-8z",
|
||
shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",
|
||
chart:"M18 20V10M12 20V4M6 20v-6"
|
||
};
|
||
function svg(n,s,c){var d=P[n]||P.activity;s=s||20;return '<svg width="'+s+'" height="'+s+'" viewBox="0 0 24 24" fill="none" stroke="'+(c||"currentColor")+'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block;vertical-align:middle"><path d="'+d+'"/></svg>';}
|
||
function hydrate(root){(root||document).querySelectorAll("[data-pw-icon]").forEach(function(el){el.innerHTML=svg(el.getAttribute("data-pw-icon"),el.getAttribute("data-size")||20,el.getAttribute("data-color"));});}
|
||
g.PwIcons={names:Object.keys(P),svg:svg,hydrate:hydrate};
|
||
})(window);`
|
||
fs.writeFileSync(path.join(outDir, 'pw-icons.min.js'), js, 'utf8')
|
||
return reportSize('pw-icons.min.js')
|
||
}
|
||
|
||
async function main() {
|
||
const manifest = {}
|
||
|
||
// 1. Plyr (Player UI, zero-dep)
|
||
manifest.plyr = {
|
||
global: 'Plyr',
|
||
category: 'media-player',
|
||
js: copyDist('plyr/dist/plyr.min.js', 'plyr.min.js'),
|
||
css: copyDist('plyr/dist/plyr.css', 'plyr.css'),
|
||
note: '首选轻量无依赖播放器 UI,配合 hls 播放 m3u8 直播/点播'
|
||
}
|
||
|
||
// 2. hls.js light build
|
||
manifest.hls = {
|
||
global: 'Hls',
|
||
category: 'streaming',
|
||
js: copyDist('hls.js/dist/hls.light.min.js', 'hls.light.min.js'),
|
||
note: 'HLS (m3u8) 离线精简版流媒体引擎'
|
||
}
|
||
|
||
// 3. ECharts (Tree-Shaken Dashboard Build!)
|
||
manifest.echarts = {
|
||
global: 'echarts',
|
||
category: 'charts',
|
||
heavy: true,
|
||
js: await bundleEntry(
|
||
`
|
||
import * as echarts from 'echarts/core';
|
||
import { LineChart, BarChart, PieChart, GaugeChart, RadarChart, ScatterChart } from 'echarts/charts';
|
||
import {
|
||
TitleComponent, TooltipComponent, GridComponent, LegendComponent,
|
||
DatasetComponent, TransformComponent, DataZoomComponent, MarkLineComponent, MarkPointComponent
|
||
} from 'echarts/components';
|
||
import { CanvasRenderer } from 'echarts/renderers';
|
||
echarts.use([
|
||
LineChart, BarChart, PieChart, GaugeChart, RadarChart, ScatterChart,
|
||
TitleComponent, TooltipComponent, GridComponent, LegendComponent,
|
||
DatasetComponent, TransformComponent, DataZoomComponent, MarkLineComponent, MarkPointComponent,
|
||
CanvasRenderer
|
||
]);
|
||
export const init = echarts.init;
|
||
export const use = echarts.use;
|
||
export const graphic = echarts.graphic;
|
||
export const registerTheme = echarts.registerTheme;
|
||
export const getInstanceByDom = echarts.getInstanceByDom;
|
||
export const dispose = echarts.dispose;
|
||
export default echarts;
|
||
`,
|
||
'echarts.custom.min.js',
|
||
'echarts'
|
||
),
|
||
note: '按需裁剪版 ECharts(含折线/柱状/饼图/仪表盘/雷达/散点 + CanvasRenderer),仅在需要复杂图表时按需加载'
|
||
}
|
||
|
||
// 4. Konva.js (2D Interactive Canvas)
|
||
manifest.konva = {
|
||
global: 'Konva',
|
||
category: 'canvas-2d',
|
||
js: copyDist('konva/konva.min.js', 'konva.min.js'),
|
||
note: '2D 交互画布引擎,适合矢量对象编排与实时动效看板'
|
||
}
|
||
|
||
// 5. Three.js (3D WebGL - heavy, use sparingly on low-end GPU)
|
||
manifest.three = {
|
||
global: 'THREE',
|
||
category: 'canvas-3d',
|
||
heavy: true,
|
||
js: await bundleEntry(
|
||
`export * from 'three';`,
|
||
'three.min.js',
|
||
'THREE'
|
||
),
|
||
note: 'Three.js 3D 渲染库,体积较大,机顶盒/低端 GPU 慎用,仅明确需要 3D 时加载'
|
||
}
|
||
|
||
// 6. Rough.js (Hand-drawn sketch style, <9KB)
|
||
manifest.rough = {
|
||
global: 'rough',
|
||
category: 'sketch',
|
||
js: await bundleEntry(
|
||
`import rough from 'roughjs/bundled/rough.esm.js'; export default rough; export const canvas = rough.canvas; export const svg = rough.svg; export const generator = rough.generator;`,
|
||
'rough.min.js',
|
||
'rough'
|
||
),
|
||
note: '手绘风格 Canvas/SVG 绘制库(超轻量 <9KB)'
|
||
}
|
||
|
||
// 7. Tailwind CSS prebuilt utility subset
|
||
manifest.tailwind = {
|
||
category: 'css',
|
||
css: generateTailwindLiteCss(),
|
||
note: '离线预编译 Tailwind 实用工具类 CSS(零 JS 运行时开销,Android 11 WebView 兼容)'
|
||
}
|
||
|
||
// 8. Day.js (~2KB)
|
||
manifest.dayjs = {
|
||
global: 'dayjs',
|
||
category: 'datetime',
|
||
js: copyDist('dayjs/dayjs.min.js', 'dayjs.min.js'),
|
||
note: '超轻量日期时间格式化与计算库(~2KB)'
|
||
}
|
||
|
||
// 9. lodash-es tree-shaken subset (~3-5KB)
|
||
manifest.lodash = {
|
||
global: '_',
|
||
category: 'utils',
|
||
js: await bundleEntry(
|
||
`
|
||
export {
|
||
debounce, throttle, cloneDeep, merge, groupBy, sortBy, orderBy,
|
||
uniq, uniqBy, chunk, clamp, pick, omit, get, set, sumBy, meanBy, keyBy, round, range
|
||
} from 'lodash-es';
|
||
`,
|
||
'lodash-lite.min.js',
|
||
'_'
|
||
),
|
||
note: '按需 Tree-Shaking 的 lodash-es 常用工具函数集(window._)'
|
||
}
|
||
|
||
// 10. Zustand vanilla (~1KB)
|
||
manifest.zustand = {
|
||
global: 'Zustand',
|
||
category: 'state',
|
||
js: await bundleEntry(
|
||
`export { createStore } from 'zustand/vanilla';`,
|
||
'zustand.min.js',
|
||
'Zustand'
|
||
),
|
||
note: '极简跨组件状态共享库(window.Zustand.createStore,~1KB)'
|
||
}
|
||
|
||
// 11. Anime.js (~6KB)
|
||
manifest.anime = {
|
||
global: 'anime',
|
||
category: 'animation',
|
||
js: copyDist('animejs/lib/anime.min.js', 'anime.min.js'),
|
||
note: '轻量动效库(仅在 CSS 动画不够用时按需引入)'
|
||
}
|
||
|
||
// 12. Ultra-light inline SVG icons (<2KB)
|
||
manifest.icons = {
|
||
global: 'PwIcons',
|
||
category: 'icons',
|
||
js: generateUltraLightIcons(),
|
||
note: '超轻量离线 SVG 图标运行时(<2KB,支持 PwIcons.svg("cpu", 20) 或 data-pw-icon 属性)'
|
||
}
|
||
|
||
fs.writeFileSync(path.join(outDir, 'manifest.json'), JSON.stringify(manifest, null, 2), 'utf8')
|
||
console.log('\n=== Bundled Offline Android Assets Summary ===')
|
||
for (const [k, v] of Object.entries(manifest)) {
|
||
const jsInfo = v.js ? `JS ${v.js.raw_kb}KB (gz ${v.js.gzip_kb}KB)` : ''
|
||
const cssInfo = v.css ? `CSS ${v.css.raw_kb}KB (gz ${v.css.gzip_kb}KB)` : ''
|
||
console.log(`- ${k.padEnd(10)} [global: ${(v.global || '-').padEnd(8)}] ${[jsInfo, cssInfo].filter(Boolean).join(' + ')}`)
|
||
}
|
||
}
|
||
|
||
main().catch((err) => {
|
||
console.error(err)
|
||
process.exit(1)
|
||
})
|