vibedgames 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/assets/align-framing.py +242 -0
- package/assets/render-model.py +406 -0
- package/assets/tilemap-editor.html +630 -0
- package/dist/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/chunk-2KVQJKIZ.js +6495 -0
- package/dist/{chunk-56OY4TEP.js → chunk-2SBBKY5C.js} +1361 -4493
- package/dist/{chunk-FC233UKH.js → chunk-2ZKS7V72.js} +16 -16
- package/dist/{chunk-BMTHAVMS.js → chunk-3HGBIUM5.js} +22 -19
- package/dist/chunk-3UGGMFJJ.js +22 -0
- package/dist/{chunk-3HUWAJQH.js → chunk-42K3BJJH.js} +93 -76
- package/dist/{chunk-ST5FC2W3.js → chunk-43P4U7CB.js} +20 -11
- package/dist/chunk-4FJXCS3K.js +741 -0
- package/dist/{chunk-WSRIF6K4.js → chunk-4UU622RK.js} +5 -4
- package/dist/chunk-5YPLKGY3.js +87 -0
- package/dist/chunk-6KXXZXSO.js +475 -0
- package/dist/chunk-7RPLQWR2.js +91 -0
- package/dist/{chunk-ZCYWDKYP.js → chunk-A556KALN.js} +14 -13
- package/dist/{chunk-UFR6G6BL.js → chunk-ABTUEIRC.js} +554 -254
- package/dist/{chunk-PEUP4MZR.js → chunk-AWJNAGPE.js} +6 -3
- package/dist/{chunk-HNRVSBRK.js → chunk-BN3Q7UEC.js} +20 -17
- package/dist/chunk-BZOMEG3X.js +412 -0
- package/dist/{chunk-ZYCSYJWX.js → chunk-COSLGSVO.js} +14 -24
- package/dist/{chunk-KZBZNTM4.js → chunk-CTY2WZQK.js} +9 -13
- package/dist/chunk-DB7WVFS7.js +80 -0
- package/dist/chunk-DOOQUFPG.js +73 -0
- package/dist/{chunk-K2U7L4RU.js → chunk-E3FJUPLT.js} +15 -21
- package/dist/chunk-E7NDOZ27.js +428 -0
- package/dist/{chunk-TBQ5BU3Q.js → chunk-F42QKWBB.js} +18 -18
- package/dist/chunk-FXXVXDTW.js +168 -0
- package/dist/{chunk-VFFOT7KD.js → chunk-G66HRVDW.js} +1 -1
- package/dist/chunk-GLEW7VJQ.js +45 -0
- package/dist/{chunk-AXTLPJ2F.js → chunk-H2C4QUTG.js} +8 -7
- package/dist/{chunk-H3IPLBXQ.js → chunk-HRKVAXNN.js} +17 -14
- package/dist/{chunk-UXCWSWWX.js → chunk-HSMG6U7J.js} +8 -7
- package/dist/chunk-HX5Q63UA.js +48 -0
- package/dist/chunk-HYOXGNWS.js +53 -0
- package/dist/chunk-I5LELJSK.js +22 -0
- package/dist/{chunk-7CXMMC5S.js → chunk-JN4WZCR7.js} +5 -4
- package/dist/{chunk-7QZSDU52.js → chunk-K36EOII3.js} +5 -4
- package/dist/chunk-KAGVI3CE.js +62 -0
- package/dist/chunk-KJK5CB6E.js +58 -0
- package/dist/chunk-KLFBAFXD.js +25 -0
- package/dist/{chunk-355VG7EO.js → chunk-LONQWRTR.js} +107 -77
- package/dist/{chunk-Z5TFZQ5U.js → chunk-LORGE2NB.js} +68 -62
- package/dist/{chunk-LY2GQ32S.js → chunk-MEAO33XW.js} +22 -20
- package/dist/{chunk-OD2MNYXD.js → chunk-MR5KIFI7.js} +23 -22
- package/dist/{chunk-2VUUMXAQ.js → chunk-N2UHAQXC.js} +18 -11
- package/dist/chunk-NCX6LYNJ.js +117 -0
- package/dist/chunk-OGX4DKIS.js +215 -0
- package/dist/chunk-OPUCUUID.js +41 -0
- package/dist/chunk-Q2QC6KAZ.js +132 -0
- package/dist/{chunk-NDHXM4PL.js → chunk-Q3XQPNF6.js} +12 -12
- package/dist/{chunk-RXHTGX7C.js → chunk-Q5NZNXJE.js} +6 -10
- package/dist/chunk-QLCVLCPM.js +126 -0
- package/dist/chunk-R2WVORGD.js +91 -0
- package/dist/chunk-RKS7SI5L.js +64 -0
- package/dist/{chunk-US6QZICZ.js → chunk-RPJR3S5S.js} +32 -18
- package/dist/chunk-RPSUFZAG.js +3307 -0
- package/dist/chunk-RRI23NK2.js +40 -0
- package/dist/chunk-S7HYWITX.js +57 -0
- package/dist/chunk-SBXCK2I2.js +48 -0
- package/dist/chunk-SUSX3QIA.js +62 -0
- package/dist/{chunk-6EWHKL7Z.js → chunk-SXYQL4GK.js} +7 -6
- package/dist/{chunk-ZI6PKVXG.js → chunk-TMPBGXT4.js} +6 -5
- package/dist/chunk-TXOE5UY5.js +72 -0
- package/dist/chunk-U6DTE5IX.js +124 -0
- package/dist/{chunk-UZM6OSW5.js → chunk-UPHB5HWO.js} +15 -13
- package/dist/chunk-UQ7VO6B3.js +91 -0
- package/dist/chunk-VB4WLJR2.js +47 -0
- package/dist/{chunk-25BAMW5X.js → chunk-VIEKOGKG.js} +18 -2
- package/dist/{chunk-LXS3NJYD.js → chunk-VZEJ2ZHE.js} +14 -15
- package/dist/{chunk-Z4Z24FWO.js → chunk-YNCYMWER.js} +8 -5
- package/dist/chunk-ZHLPE6LI.js +71 -0
- package/dist/index.js +39 -36
- package/package.json +31 -16
- package/templates/none/src/main.ts +4 -0
- package/templates/none/vite.config.ts +0 -2
- package/templates/phaser/src/main.ts +0 -1
- package/templates/phaser/src/scenes/game-scene.ts +10 -8
- package/templates/phaser/vite.config.ts +0 -2
- package/templates/react-r3f/src/app.tsx +3 -1
- package/templates/react-r3f/src/main.tsx +1 -0
- package/templates/react-r3f/vite.config.ts +0 -2
- package/templates/threejs/src/main.ts +10 -1
- package/templates/threejs/vite.config.ts +0 -2
- package/LICENSE +0 -21
- package/dist/chunk-J6PKNPI2.js +0 -26
|
@@ -9,10 +9,11 @@ import {
|
|
|
9
9
|
isNewerVersion,
|
|
10
10
|
markUpdateChecked,
|
|
11
11
|
maybeScheduleAutoUpdate
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-N2UHAQXC.js";
|
|
13
|
+
import "./chunk-JN4WZCR7.js";
|
|
14
|
+
import "./chunk-Q5NZNXJE.js";
|
|
15
|
+
import "./chunk-RPSUFZAG.js";
|
|
16
|
+
import "./chunk-2SBBKY5C.js";
|
|
16
17
|
import "./chunk-GKDUYJ7R.js";
|
|
17
18
|
export {
|
|
18
19
|
fetchLatestVersion,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
MARKER,
|
|
9
|
+
getFlag,
|
|
10
|
+
normalizeFactory,
|
|
11
|
+
parseArgs
|
|
12
|
+
} from "./chunk-2KVQJKIZ.js";
|
|
13
|
+
import "./chunk-2SBBKY5C.js";
|
|
14
|
+
import "./chunk-GKDUYJ7R.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/asset/normalize-factory.ts
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
+
var oneDecimal = (value = 0) => {
|
|
19
|
+
const scaled = value * 10;
|
|
20
|
+
const floor = Math.floor(scaled);
|
|
21
|
+
const diff = scaled - floor;
|
|
22
|
+
let rounded = floor;
|
|
23
|
+
if (diff > 0.5 || diff === 0.5 && floor % 2 !== 0) {
|
|
24
|
+
rounded = floor + 1;
|
|
25
|
+
}
|
|
26
|
+
return (rounded / 10).toFixed(1);
|
|
27
|
+
};
|
|
28
|
+
var assert = (condition = false, message = "") => {
|
|
29
|
+
if (!condition) {
|
|
30
|
+
process.stderr.write(`${message}
|
|
31
|
+
`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var selftest = () => {
|
|
36
|
+
const sample = `import * as THREE from 'three';
|
|
37
|
+
node_a.userData.sculptComponent = {"id": "a", "big": "payload"};
|
|
38
|
+
node_a.userData.actionProfile = {"pivot": {}};
|
|
39
|
+
node_a.name = 'keep me';
|
|
40
|
+
`;
|
|
41
|
+
const once = normalizeFactory(sample);
|
|
42
|
+
assert(!once.includes("sculptComponent"), "sculptComponent survived");
|
|
43
|
+
assert(!once.includes("actionProfile"), "actionProfile survived");
|
|
44
|
+
assert(once.includes("keep me"), "dropped an unrelated line");
|
|
45
|
+
assert(once.startsWith(MARKER), "missing generated marker");
|
|
46
|
+
assert(normalizeFactory(once) === once, "not idempotent");
|
|
47
|
+
const kept = normalizeFactory(sample, true);
|
|
48
|
+
assert(kept.includes("actionProfile"), "--keep-action-profile did not keep it");
|
|
49
|
+
assert(!kept.includes("sculptComponent"), "sculptComponent survived");
|
|
50
|
+
console.log("selftest ok");
|
|
51
|
+
process.exit(0);
|
|
52
|
+
};
|
|
53
|
+
var run = (argv) => {
|
|
54
|
+
const args = parseArgs([...argv], {
|
|
55
|
+
booleans: ["keep-action-profile", "selftest"]
|
|
56
|
+
});
|
|
57
|
+
if (getFlag(args, "selftest")) {
|
|
58
|
+
selftest();
|
|
59
|
+
}
|
|
60
|
+
const files = args.positionals;
|
|
61
|
+
if (files.length === 0) {
|
|
62
|
+
process.stderr.write("pass at least one generated factory, or --selftest\n");
|
|
63
|
+
process.exit(2);
|
|
64
|
+
}
|
|
65
|
+
const keepActionProfile = getFlag(args, "keep-action-profile");
|
|
66
|
+
let failed = false;
|
|
67
|
+
for (const path of files) {
|
|
68
|
+
if (!existsSync(path)) {
|
|
69
|
+
process.stderr.write(`missing: ${path}
|
|
70
|
+
`);
|
|
71
|
+
failed = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const before = readFileSync(path, "utf-8");
|
|
75
|
+
const after = normalizeFactory(before, keepActionProfile);
|
|
76
|
+
writeFileSync(path, after);
|
|
77
|
+
const saved = before.length - after.length;
|
|
78
|
+
const pct = before.length ? 100 * saved / before.length : 0;
|
|
79
|
+
console.log(
|
|
80
|
+
`normalized ${path}: ${oneDecimal(before.length / 1024)}KB -> ${oneDecimal(after.length / 1024)}KB (-${oneDecimal(pct)}%)`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
process.exit(failed ? 1 : 0);
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
run
|
|
87
|
+
};
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
loadProjectChromium
|
|
9
|
+
} from "./chunk-KLFBAFXD.js";
|
|
10
|
+
import "./chunk-GKDUYJ7R.js";
|
|
11
|
+
|
|
12
|
+
// src/checks/canvas.ts
|
|
13
|
+
import { writeFileSync } from "node:fs";
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
15
|
+
import { inflateSync } from "node:zlib";
|
|
16
|
+
var USAGE = "usage: vg check canvas <url|file> [--selector css] [--out png] [--wait ms] [--min-std n] [--mobile] [--json]";
|
|
17
|
+
var RENDER_BUDGETS = {
|
|
18
|
+
desktop: { calls: 300, geometries: 300, textures: 60, triangles: 75e4 },
|
|
19
|
+
mobile: { calls: 150, geometries: 200, textures: 40, triangles: 3e5 }
|
|
20
|
+
};
|
|
21
|
+
var parseArgs = (argv) => {
|
|
22
|
+
const opts = {
|
|
23
|
+
json: false,
|
|
24
|
+
minStd: 4,
|
|
25
|
+
mobile: false,
|
|
26
|
+
out: null,
|
|
27
|
+
selector: "canvas",
|
|
28
|
+
target: null,
|
|
29
|
+
wait: 1500
|
|
30
|
+
};
|
|
31
|
+
const rest = [];
|
|
32
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
33
|
+
const a = argv[i] ?? "";
|
|
34
|
+
if (a === "--selector") {
|
|
35
|
+
opts.selector = argv[i += 1] ?? "";
|
|
36
|
+
} else if (a === "--out") {
|
|
37
|
+
opts.out = argv[i += 1] ?? null;
|
|
38
|
+
} else if (a === "--wait") {
|
|
39
|
+
opts.wait = Number(argv[i += 1]);
|
|
40
|
+
} else if (a === "--min-std") {
|
|
41
|
+
opts.minStd = Number(argv[i += 1]);
|
|
42
|
+
} else if (a === "--json") {
|
|
43
|
+
opts.json = true;
|
|
44
|
+
} else if (a === "--mobile") {
|
|
45
|
+
opts.mobile = true;
|
|
46
|
+
} else {
|
|
47
|
+
rest.push(a);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
opts.target = rest[0] ?? null;
|
|
51
|
+
if (!Number.isFinite(opts.wait) || opts.wait < 0) {
|
|
52
|
+
throw new Error(`--wait must be a non-negative number (got ${opts.wait})`);
|
|
53
|
+
}
|
|
54
|
+
if (!Number.isFinite(opts.minStd) || opts.minStd < 0) {
|
|
55
|
+
throw new Error(`--min-std must be a non-negative number (got ${opts.minStd})`);
|
|
56
|
+
}
|
|
57
|
+
return opts;
|
|
58
|
+
};
|
|
59
|
+
var toUrl = (target) => {
|
|
60
|
+
if (/^https?:\/\//u.test(target) || target.startsWith("file://")) {
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
63
|
+
return pathToFileURL(target).href;
|
|
64
|
+
};
|
|
65
|
+
var paeth = (a, b, c) => {
|
|
66
|
+
const p = a + b - c;
|
|
67
|
+
const pa = Math.abs(p - a);
|
|
68
|
+
const pb = Math.abs(p - b);
|
|
69
|
+
const pc = Math.abs(p - c);
|
|
70
|
+
if (pa <= pb && pa <= pc) {
|
|
71
|
+
return a;
|
|
72
|
+
}
|
|
73
|
+
return pb <= pc ? b : c;
|
|
74
|
+
};
|
|
75
|
+
var CHANNELS = /* @__PURE__ */ new Map([
|
|
76
|
+
[0, 1],
|
|
77
|
+
[2, 3],
|
|
78
|
+
[4, 2],
|
|
79
|
+
[6, 4]
|
|
80
|
+
]);
|
|
81
|
+
var unfilter = (filter, v, a, b, c) => {
|
|
82
|
+
switch (filter) {
|
|
83
|
+
case 0: {
|
|
84
|
+
return v;
|
|
85
|
+
}
|
|
86
|
+
case 1: {
|
|
87
|
+
return v + a;
|
|
88
|
+
}
|
|
89
|
+
case 2: {
|
|
90
|
+
return v + b;
|
|
91
|
+
}
|
|
92
|
+
case 3: {
|
|
93
|
+
return v + Math.floor((a + b) / 2);
|
|
94
|
+
}
|
|
95
|
+
case 4: {
|
|
96
|
+
return v + paeth(a, b, c);
|
|
97
|
+
}
|
|
98
|
+
default: {
|
|
99
|
+
throw new Error(`bad filter ${filter}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var readChunks = (buf) => {
|
|
104
|
+
let off = 8;
|
|
105
|
+
let bitDepth = 8;
|
|
106
|
+
let colorType = 6;
|
|
107
|
+
let height = 0;
|
|
108
|
+
let width = 0;
|
|
109
|
+
const idat = [];
|
|
110
|
+
while (off < buf.length) {
|
|
111
|
+
const len = buf.readUInt32BE(off);
|
|
112
|
+
const type = buf.toString("ascii", off + 4, off + 8);
|
|
113
|
+
const data = buf.subarray(off + 8, off + 8 + len);
|
|
114
|
+
if (type === "IHDR") {
|
|
115
|
+
width = data.readUInt32BE(0);
|
|
116
|
+
height = data.readUInt32BE(4);
|
|
117
|
+
bitDepth = data.readUInt8(8);
|
|
118
|
+
colorType = data.readUInt8(9);
|
|
119
|
+
if (data.readUInt8(12) !== 0) {
|
|
120
|
+
throw new Error("interlaced PNG unsupported");
|
|
121
|
+
}
|
|
122
|
+
} else if (type === "IDAT") {
|
|
123
|
+
idat.push(data);
|
|
124
|
+
} else if (type === "IEND") {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
off += 12 + len;
|
|
128
|
+
}
|
|
129
|
+
return { bitDepth, colorType, height, idat, width };
|
|
130
|
+
};
|
|
131
|
+
var decodePng = (buf) => {
|
|
132
|
+
if (buf.readUInt32BE(0) !== 2303741511) {
|
|
133
|
+
throw new Error("not a PNG");
|
|
134
|
+
}
|
|
135
|
+
const { bitDepth, colorType, height, idat, width } = readChunks(buf);
|
|
136
|
+
if (bitDepth !== 8) {
|
|
137
|
+
throw new Error(`bit depth ${bitDepth} unsupported`);
|
|
138
|
+
}
|
|
139
|
+
const channels = CHANNELS.get(colorType);
|
|
140
|
+
if (channels === void 0) {
|
|
141
|
+
throw new Error(`color type ${colorType} unsupported`);
|
|
142
|
+
}
|
|
143
|
+
const raw = inflateSync(Buffer.concat(idat));
|
|
144
|
+
const stride = width * channels;
|
|
145
|
+
const out = Buffer.alloc(height * stride);
|
|
146
|
+
let pos = 0;
|
|
147
|
+
for (let y = 0; y < height; y += 1) {
|
|
148
|
+
const filter = raw[pos] ?? 0;
|
|
149
|
+
pos += 1;
|
|
150
|
+
for (let x = 0; x < stride; x += 1) {
|
|
151
|
+
const v = raw[pos] ?? 0;
|
|
152
|
+
pos += 1;
|
|
153
|
+
const a = x >= channels ? out[y * stride + x - channels] ?? 0 : 0;
|
|
154
|
+
const b = y > 0 ? out[(y - 1) * stride + x] ?? 0 : 0;
|
|
155
|
+
const c = x >= channels && y > 0 ? out[(y - 1) * stride + x - channels] ?? 0 : 0;
|
|
156
|
+
out[y * stride + x] = unfilter(filter, v, a, b, c) % 256;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { channels, data: out, height, width };
|
|
160
|
+
};
|
|
161
|
+
var analyze = ({
|
|
162
|
+
width,
|
|
163
|
+
height,
|
|
164
|
+
channels,
|
|
165
|
+
data
|
|
166
|
+
}) => {
|
|
167
|
+
const stride = width * channels;
|
|
168
|
+
const stepX = Math.max(1, Math.floor(width / 200));
|
|
169
|
+
const stepY = Math.max(1, Math.floor(height / 200));
|
|
170
|
+
let n = 0;
|
|
171
|
+
let opaque = 0;
|
|
172
|
+
let sum = 0;
|
|
173
|
+
let sumSq = 0;
|
|
174
|
+
for (let y = 0; y < height; y += stepY) {
|
|
175
|
+
for (let x = 0; x < width; x += stepX) {
|
|
176
|
+
const i = y * stride + x * channels;
|
|
177
|
+
let alpha = 255;
|
|
178
|
+
let b = 0;
|
|
179
|
+
let g = 0;
|
|
180
|
+
const r = data[i] ?? 0;
|
|
181
|
+
if (channels >= 3) {
|
|
182
|
+
g = data[i + 1] ?? 0;
|
|
183
|
+
b = data[i + 2] ?? 0;
|
|
184
|
+
alpha = channels === 4 ? data[i + 3] ?? 0 : 255;
|
|
185
|
+
} else {
|
|
186
|
+
g = r;
|
|
187
|
+
b = r;
|
|
188
|
+
alpha = channels === 2 ? data[i + 1] ?? 0 : 255;
|
|
189
|
+
}
|
|
190
|
+
const lum = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
191
|
+
sum += lum;
|
|
192
|
+
sumSq += lum * lum;
|
|
193
|
+
if (alpha > 8) {
|
|
194
|
+
opaque += 1;
|
|
195
|
+
}
|
|
196
|
+
n += 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (n === 0) {
|
|
200
|
+
const empty = { meanLum: 0, opaqueFraction: 0, sampled: 0, stdLum: 0 };
|
|
201
|
+
return empty;
|
|
202
|
+
}
|
|
203
|
+
const mean = sum / n;
|
|
204
|
+
const std = Math.sqrt(Math.max(0, sumSq / n - mean * mean));
|
|
205
|
+
const stats = { meanLum: mean, opaqueFraction: opaque / n, sampled: n, stdLum: std };
|
|
206
|
+
return stats;
|
|
207
|
+
};
|
|
208
|
+
var PAGE_OPTIONS = {
|
|
209
|
+
desktop: { viewport: { height: 720, width: 1280 } },
|
|
210
|
+
mobile: {
|
|
211
|
+
deviceScaleFactor: 3,
|
|
212
|
+
hasTouch: true,
|
|
213
|
+
isMobile: true,
|
|
214
|
+
viewport: { height: 844, width: 390 }
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var renderBudget = (rendererInfo, tier) => {
|
|
218
|
+
if (rendererInfo === null) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return Object.entries(RENDER_BUDGETS[tier]).map(([metric, limit]) => {
|
|
222
|
+
const value = Object.hasOwn(rendererInfo, metric) ? rendererInfo[metric] : void 0;
|
|
223
|
+
const actual = value !== void 0 && Number.isFinite(value) ? value : null;
|
|
224
|
+
const row = { actual, limit, metric, ok: actual === null ? null : actual <= limit };
|
|
225
|
+
return row;
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
var launchBrowser = async (chromium, channels = ["chrome", "chromium"]) => {
|
|
229
|
+
const [channel, ...rest] = channels;
|
|
230
|
+
if (channel !== void 0) {
|
|
231
|
+
try {
|
|
232
|
+
return await chromium.launch({ channel });
|
|
233
|
+
} catch {
|
|
234
|
+
return await launchBrowser(chromium, rest);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
console.error(
|
|
238
|
+
[
|
|
239
|
+
'warning: neither channel "chrome" nor "chromium" is available; falling back to the bundled headless shell.',
|
|
240
|
+
" Rendering will be software (SwiftShader) and any FPS/frame-time evidence is invalid.",
|
|
241
|
+
" Fix with: npx playwright install chromium"
|
|
242
|
+
].join("\n")
|
|
243
|
+
);
|
|
244
|
+
return await chromium.launch();
|
|
245
|
+
};
|
|
246
|
+
var readGpuInfo = async (page) => {
|
|
247
|
+
const info = await page.evaluate(() => {
|
|
248
|
+
const canvas = document.querySelector("canvas");
|
|
249
|
+
let gl = null;
|
|
250
|
+
try {
|
|
251
|
+
gl = canvas?.getContext("webgl2") ?? canvas?.getContext("webgl") ?? null;
|
|
252
|
+
} catch {
|
|
253
|
+
gl = null;
|
|
254
|
+
}
|
|
255
|
+
if (!gl) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const debug = gl.getExtension("WEBGL_debug_renderer_info");
|
|
259
|
+
const read = (name) => {
|
|
260
|
+
const value = gl?.getParameter(name);
|
|
261
|
+
return String(value) === value ? value : null;
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
renderer: read(debug === null ? gl.RENDERER : debug.UNMASKED_RENDERER_WEBGL),
|
|
265
|
+
vendor: read(debug === null ? gl.VENDOR : debug.UNMASKED_VENDOR_WEBGL)
|
|
266
|
+
};
|
|
267
|
+
}).catch(() => null);
|
|
268
|
+
const renderer = info?.renderer ?? null;
|
|
269
|
+
if (renderer === null || renderer === "") {
|
|
270
|
+
const unknown = { renderer: null, softwareRendered: null, vendor: null };
|
|
271
|
+
return unknown;
|
|
272
|
+
}
|
|
273
|
+
const gpu = {
|
|
274
|
+
renderer,
|
|
275
|
+
softwareRendered: /swiftshader|llvmpipe|software|basic render/iu.test(renderer),
|
|
276
|
+
vendor: info?.vendor ?? null
|
|
277
|
+
};
|
|
278
|
+
return gpu;
|
|
279
|
+
};
|
|
280
|
+
var failureReason = ({
|
|
281
|
+
blankLum,
|
|
282
|
+
minStd,
|
|
283
|
+
nearEmpty,
|
|
284
|
+
pageErrors,
|
|
285
|
+
stats
|
|
286
|
+
}) => {
|
|
287
|
+
if (pageErrors.length > 0) {
|
|
288
|
+
return `uncaught page error: ${pageErrors[0]}`;
|
|
289
|
+
}
|
|
290
|
+
if (nearEmpty) {
|
|
291
|
+
return `near-empty canvas (opaque ${(stats.opaqueFraction * 100).toFixed(1)}% \u2264 1%)`;
|
|
292
|
+
}
|
|
293
|
+
if (blankLum) {
|
|
294
|
+
return `blank/solid (stdLum ${stats.stdLum.toFixed(2)} < ${minStd})`;
|
|
295
|
+
}
|
|
296
|
+
return "rendered non-blank content";
|
|
297
|
+
};
|
|
298
|
+
var messageOf = (error) => error instanceof Error && error.message !== "" ? error.message : String(error);
|
|
299
|
+
var readOptions = (argv) => {
|
|
300
|
+
try {
|
|
301
|
+
return parseArgs(argv);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.error(messageOf(error instanceof Error ? error : String(error)));
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var main = async (argv) => {
|
|
308
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
309
|
+
console.log(USAGE);
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
const opts = readOptions([...argv]);
|
|
313
|
+
if (opts === null) {
|
|
314
|
+
return 2;
|
|
315
|
+
}
|
|
316
|
+
const { target } = opts;
|
|
317
|
+
if (target === null || target === "") {
|
|
318
|
+
console.error(USAGE);
|
|
319
|
+
return 2;
|
|
320
|
+
}
|
|
321
|
+
const chromium = await loadProjectChromium();
|
|
322
|
+
if (chromium === null) {
|
|
323
|
+
console.error(
|
|
324
|
+
"Playwright not found. Install it: pnpm add -D playwright (Chromium is pre-resolved in this environment)."
|
|
325
|
+
);
|
|
326
|
+
return 2;
|
|
327
|
+
}
|
|
328
|
+
let browser = null;
|
|
329
|
+
const consoleErrors = [];
|
|
330
|
+
const pageErrors = [];
|
|
331
|
+
try {
|
|
332
|
+
browser = await launchBrowser(chromium);
|
|
333
|
+
const tier = opts.mobile ? "mobile" : "desktop";
|
|
334
|
+
const page = await browser.newPage(PAGE_OPTIONS[tier]);
|
|
335
|
+
page.on("console", (m) => {
|
|
336
|
+
if (m.type() === "error") {
|
|
337
|
+
consoleErrors.push(m.text());
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
page.on("pageerror", (e) => {
|
|
341
|
+
pageErrors.push(String(e));
|
|
342
|
+
});
|
|
343
|
+
await page.goto(toUrl(target), { timeout: 3e4, waitUntil: "load" });
|
|
344
|
+
await page.waitForTimeout(opts.wait);
|
|
345
|
+
const canvas = await page.$(opts.selector);
|
|
346
|
+
if (canvas === null) {
|
|
347
|
+
report(opts, {
|
|
348
|
+
consoleErrors,
|
|
349
|
+
ok: false,
|
|
350
|
+
pageErrors,
|
|
351
|
+
reason: `no element matching "${opts.selector}"`
|
|
352
|
+
});
|
|
353
|
+
return 2;
|
|
354
|
+
}
|
|
355
|
+
const png = await canvas.screenshot();
|
|
356
|
+
if (opts.out !== null && opts.out !== "") {
|
|
357
|
+
writeFileSync(opts.out, png);
|
|
358
|
+
}
|
|
359
|
+
const rendererInfo = await page.evaluate(() => {
|
|
360
|
+
const diagnostics = globalThis.__GAME_DIAGNOSTICS__;
|
|
361
|
+
const renderer = diagnostics !== void 0 && "renderer" in diagnostics ? diagnostics.renderer : null;
|
|
362
|
+
const present = Boolean(renderer);
|
|
363
|
+
if (!present) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const fields = renderer instanceof Object ? Object.entries(renderer) : [];
|
|
367
|
+
return Object.fromEntries(
|
|
368
|
+
fields.filter((field) => Number(field[1]) === field[1])
|
|
369
|
+
);
|
|
370
|
+
}).catch(() => null);
|
|
371
|
+
const budget = renderBudget(rendererInfo, tier);
|
|
372
|
+
const gpu = await readGpuInfo(page);
|
|
373
|
+
const stats = analyze(decodePng(png));
|
|
374
|
+
const blankLum = !(stats.stdLum >= opts.minStd);
|
|
375
|
+
const nearEmpty = !(stats.opaqueFraction > 0.01);
|
|
376
|
+
const ok = !blankLum && !nearEmpty && pageErrors.length === 0;
|
|
377
|
+
const reason = failureReason({ blankLum, minStd: opts.minStd, nearEmpty, pageErrors, stats });
|
|
378
|
+
report(opts, {
|
|
379
|
+
ok,
|
|
380
|
+
reason,
|
|
381
|
+
...stats,
|
|
382
|
+
budget,
|
|
383
|
+
consoleErrors,
|
|
384
|
+
gpu,
|
|
385
|
+
out: opts.out,
|
|
386
|
+
pageErrors,
|
|
387
|
+
tier
|
|
388
|
+
});
|
|
389
|
+
return ok ? 0 : 1;
|
|
390
|
+
} catch (error) {
|
|
391
|
+
report(opts, {
|
|
392
|
+
consoleErrors,
|
|
393
|
+
ok: false,
|
|
394
|
+
pageErrors,
|
|
395
|
+
reason: messageOf(error instanceof Error ? error : String(error))
|
|
396
|
+
});
|
|
397
|
+
return 2;
|
|
398
|
+
} finally {
|
|
399
|
+
if (browser !== null) {
|
|
400
|
+
await browser.close();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
var reportGpu = (gpu) => {
|
|
405
|
+
if (gpu.renderer === null) {
|
|
406
|
+
console.log(" gpu: no WebGL context on the canvas \u2014 renderer unknown");
|
|
407
|
+
} else if (gpu.softwareRendered === true) {
|
|
408
|
+
console.log(
|
|
409
|
+
` gpu: ${gpu.renderer} (SOFTWARE) \u2014 pixel/budget/functional checks valid; FPS and frame-time numbers from this run are NOT performance evidence`
|
|
410
|
+
);
|
|
411
|
+
} else {
|
|
412
|
+
console.log(` gpu: ${gpu.renderer}`);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var reportBudget = (budget, tier) => {
|
|
416
|
+
const over = budget.filter((row) => row.ok === false);
|
|
417
|
+
const missing = budget.filter((row) => row.ok === null);
|
|
418
|
+
if (over.length > 0) {
|
|
419
|
+
console.log(` render budget (${tier} tier, advisory) \u2014 OVER:`);
|
|
420
|
+
for (const row of over) {
|
|
421
|
+
console.log(` - ${row.metric}: ${row.actual ?? "null"} > ${row.limit}`);
|
|
422
|
+
}
|
|
423
|
+
} else if (missing.length === budget.length) {
|
|
424
|
+
console.log(
|
|
425
|
+
` render budget (${tier} tier): diagnostics present but no numeric metrics \u2014 not validated`
|
|
426
|
+
);
|
|
427
|
+
} else {
|
|
428
|
+
console.log(` render budget (${tier} tier): within limits`);
|
|
429
|
+
}
|
|
430
|
+
if (missing.length > 0 && missing.length < budget.length) {
|
|
431
|
+
console.log(
|
|
432
|
+
` (not reported by diagnostics: ${missing.map((row) => row.metric).join(", ")})`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var report = (opts, result) => {
|
|
437
|
+
if (opts.json) {
|
|
438
|
+
console.log(JSON.stringify(result, null, 2));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
console.log(`${result.ok ? "PASS" : "FAIL"} \u2014 ${result.reason}`);
|
|
442
|
+
const { meanLum, opaqueFraction, stdLum } = result;
|
|
443
|
+
if (stdLum !== void 0 && meanLum !== void 0 && opaqueFraction !== void 0) {
|
|
444
|
+
console.log(
|
|
445
|
+
` luminance stddev: ${stdLum.toFixed(2)} mean: ${meanLum.toFixed(1)} opaque: ${(opaqueFraction * 100).toFixed(1)}%`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
if (result.out !== void 0 && result.out !== null && result.out !== "") {
|
|
449
|
+
console.log(` screenshot: ${result.out}`);
|
|
450
|
+
}
|
|
451
|
+
if (result.gpu !== void 0) {
|
|
452
|
+
reportGpu(result.gpu);
|
|
453
|
+
}
|
|
454
|
+
if (result.budget !== void 0 && result.budget !== null) {
|
|
455
|
+
reportBudget(result.budget, result.tier ?? "desktop");
|
|
456
|
+
}
|
|
457
|
+
if (result.pageErrors.length > 0) {
|
|
458
|
+
console.log(` uncaught page errors (${result.pageErrors.length}):`);
|
|
459
|
+
for (const e of result.pageErrors.slice(0, 5)) {
|
|
460
|
+
console.log(` - ${e}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (result.consoleErrors.length > 0) {
|
|
464
|
+
console.log(` console errors (${result.consoleErrors.length}, advisory):`);
|
|
465
|
+
for (const e of result.consoleErrors.slice(0, 5)) {
|
|
466
|
+
console.log(` - ${e}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var run = async (argv) => {
|
|
471
|
+
process.exit(await main(argv));
|
|
472
|
+
};
|
|
473
|
+
export {
|
|
474
|
+
run
|
|
475
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
Bitmap,
|
|
9
|
+
fail,
|
|
10
|
+
failUsage,
|
|
11
|
+
getInt,
|
|
12
|
+
getString,
|
|
13
|
+
main,
|
|
14
|
+
parseArgs,
|
|
15
|
+
readImageSize
|
|
16
|
+
} from "./chunk-2KVQJKIZ.js";
|
|
17
|
+
import "./chunk-2SBBKY5C.js";
|
|
18
|
+
import "./chunk-GKDUYJ7R.js";
|
|
19
|
+
|
|
20
|
+
// src/commands/asset/image-util.ts
|
|
21
|
+
var parseSize = (text = "") => {
|
|
22
|
+
const match = /^(?<w>\d+)\s*x\s*(?<h>\d+)$/iu.exec(text.trim());
|
|
23
|
+
if (!match) {
|
|
24
|
+
failUsage(`--size must be WxH, e.g. 128x128 (got "${text}")`);
|
|
25
|
+
}
|
|
26
|
+
const width = Number(match?.groups?.w);
|
|
27
|
+
const height = Number(match?.groups?.h);
|
|
28
|
+
if (width < 1 || height < 1) {
|
|
29
|
+
failUsage(`--size must be at least 1x1 (got "${text}")`);
|
|
30
|
+
}
|
|
31
|
+
return { height, width };
|
|
32
|
+
};
|
|
33
|
+
var run = (argv) => {
|
|
34
|
+
main(() => {
|
|
35
|
+
const args = parseArgs([...argv], {
|
|
36
|
+
values: ["factor", "size"]
|
|
37
|
+
});
|
|
38
|
+
const resize = () => {
|
|
39
|
+
const [, input = "", output = ""] = args.positionals;
|
|
40
|
+
if (input === "" || output === "") {
|
|
41
|
+
failUsage("Usage: vg asset image-util resize <in.png> <out.png> --size WxH");
|
|
42
|
+
}
|
|
43
|
+
const spec = getString(args, "size") ?? "";
|
|
44
|
+
if (spec === "") {
|
|
45
|
+
failUsage("--size is required, e.g. --size 128x128");
|
|
46
|
+
}
|
|
47
|
+
const { width, height } = parseSize(spec);
|
|
48
|
+
Bitmap.fromFile(input).resize(width, height, "lanczos").toFile(output);
|
|
49
|
+
console.log(`${input} -> ${output} (${width}x${height}, lanczos)`);
|
|
50
|
+
};
|
|
51
|
+
const size = () => {
|
|
52
|
+
const paths = args.positionals.slice(1);
|
|
53
|
+
if (paths.length === 0) {
|
|
54
|
+
failUsage("Usage: vg asset image-util size <file.png> [...]");
|
|
55
|
+
}
|
|
56
|
+
for (const path of paths) {
|
|
57
|
+
const dims = readImageSize(path) ?? fail(`could not read image dimensions: ${path}`);
|
|
58
|
+
console.log(
|
|
59
|
+
paths.length === 1 ? `${dims.width}x${dims.height}` : `${dims.width}x${dims.height} ${path}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const upscale = () => {
|
|
64
|
+
const [, input = "", output = ""] = args.positionals;
|
|
65
|
+
if (input === "" || output === "") {
|
|
66
|
+
failUsage("Usage: vg asset image-util upscale <in.png> <out.png> --factor 8");
|
|
67
|
+
}
|
|
68
|
+
const factor = getInt(args, "factor", 8);
|
|
69
|
+
if (!Number.isInteger(factor) || factor < 1) {
|
|
70
|
+
fail("--factor must be a positive integer");
|
|
71
|
+
}
|
|
72
|
+
const image = Bitmap.fromFile(input);
|
|
73
|
+
image.resize(image.width * factor, image.height * factor, "nearest").toFile(output);
|
|
74
|
+
console.log(
|
|
75
|
+
`${input} -> ${output} (${image.width * factor}x${image.height * factor}, x${factor} nearest)`
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
const mode = (/* @__PURE__ */ new Map([
|
|
79
|
+
["resize", resize],
|
|
80
|
+
["size", size],
|
|
81
|
+
["upscale", upscale]
|
|
82
|
+
])).get(args.positionals[0] ?? "");
|
|
83
|
+
if (mode === void 0) {
|
|
84
|
+
failUsage("Usage: vg asset image-util <size|upscale|resize> ...");
|
|
85
|
+
}
|
|
86
|
+
mode?.();
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
run
|
|
91
|
+
};
|