webwallgl 1.0.0 → 1.1.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.en.md +78 -3
- package/README.md +77 -3
- package/package.json +1 -1
- package/types.d.ts +9 -1
- package/webwallgl.d.ts +2 -2
- package/webwallgl.global.js +1548 -139
- package/webwallgl.global.js.map +1 -1
- package/webwallgl.global.min.js +1241 -33
- package/webwallgl.global.min.js.map +1 -1
- package/webwallgl.min.mjs +1241 -33
- package/webwallgl.min.mjs.map +1 -1
- package/webwallgl.mjs +1548 -139
- package/webwallgl.mjs.map +1 -1
package/webwallgl.mjs
CHANGED
|
@@ -29,7 +29,20 @@ function createRuntime(opts) {
|
|
|
29
29
|
window.__blockContextMenu = (doc) => doc.addEventListener("contextmenu", block, true);
|
|
30
30
|
})();
|
|
31
31
|
function clear(rt) {
|
|
32
|
-
if (rt.
|
|
32
|
+
if (rt.iframe) {
|
|
33
|
+
try {
|
|
34
|
+
rt.iframe.contentWindow?.location.replace("about:blank");
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (rt.wrap) {
|
|
39
|
+
rt.wrap.innerHTML = "";
|
|
40
|
+
} else if (rt.iframe?.isConnected) {
|
|
41
|
+
try {
|
|
42
|
+
rt.iframe.remove();
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
if (rt.raf !== void 0) cancelAnimationFrame(rt.raf);
|
|
34
47
|
rt.raf = void 0;
|
|
35
48
|
for (const p of rt.videoPairs ?? []) p.destroy();
|
|
@@ -37,6 +50,7 @@ function clear(rt) {
|
|
|
37
50
|
if (rt.sceneCleanup) rt.sceneCleanup();
|
|
38
51
|
rt.sceneCleanup = void 0;
|
|
39
52
|
rt.sceneCtl = void 0;
|
|
53
|
+
rt.pointerCtl = void 0;
|
|
40
54
|
if (rt.renderer) {
|
|
41
55
|
rt.renderer.dispose?.();
|
|
42
56
|
rt.renderer = void 0;
|
|
@@ -120,7 +134,7 @@ function reportDiag(rt, cfg, msg) {
|
|
|
120
134
|
} catch {
|
|
121
135
|
}
|
|
122
136
|
try {
|
|
123
|
-
const origin = cfg.mediaBase ? new URL(cfg.mediaBase).origin : "";
|
|
137
|
+
const origin = cfg.mediaBase ? new URL(cfg.mediaBase, window.location.href).origin : "";
|
|
124
138
|
if (origin) {
|
|
125
139
|
const img = new Image();
|
|
126
140
|
img.src = `${origin}/diag?msg=${encodeURIComponent(`scene ${cfg.src ?? "?"}: ${msg.slice(0, 500)}`)}`;
|
|
@@ -863,6 +877,31 @@ function parseNum(v, dflt) {
|
|
|
863
877
|
}
|
|
864
878
|
return dflt;
|
|
865
879
|
}
|
|
880
|
+
function isRenderInert(o) {
|
|
881
|
+
if (!o) return false;
|
|
882
|
+
return !o.image && !o.model && !o.particle && o.text == null && !o.size;
|
|
883
|
+
}
|
|
884
|
+
function composeChildTransform(parentWorld, childLocal, parentScalePropagates) {
|
|
885
|
+
const pscale = parentScalePropagates ? parentWorld.scale : [1, 1, 1];
|
|
886
|
+
const ca = (parentWorld.angles[2] || 0) * Math.PI / 180;
|
|
887
|
+
const cos = Math.cos(ca);
|
|
888
|
+
const sin = Math.sin(ca);
|
|
889
|
+
const ox = childLocal.origin[0] * pscale[0];
|
|
890
|
+
const oy = childLocal.origin[1] * pscale[1];
|
|
891
|
+
return {
|
|
892
|
+
origin: [
|
|
893
|
+
parentWorld.origin[0] + ox * cos - oy * sin,
|
|
894
|
+
parentWorld.origin[1] + ox * sin + oy * cos,
|
|
895
|
+
parentWorld.origin[2] + (childLocal.origin[2] || 0)
|
|
896
|
+
],
|
|
897
|
+
scale: [
|
|
898
|
+
pscale[0] * childLocal.scale[0],
|
|
899
|
+
pscale[1] * childLocal.scale[1],
|
|
900
|
+
pscale[2] * childLocal.scale[2]
|
|
901
|
+
],
|
|
902
|
+
angles: [childLocal.angles[0], childLocal.angles[1], (parentWorld.angles[2] || 0) + childLocal.angles[2]]
|
|
903
|
+
};
|
|
904
|
+
}
|
|
866
905
|
function parseScene(sceneJson, project) {
|
|
867
906
|
const properties = project && project.general && project.general.properties || {};
|
|
868
907
|
const objects = sceneJson.objects || [];
|
|
@@ -879,6 +918,11 @@ function parseScene(sceneJson, project) {
|
|
|
879
918
|
scale: parseVec3(o.scale || "1 1 1"),
|
|
880
919
|
angles: parseVec3(o.angles || "0 0 0")
|
|
881
920
|
}));
|
|
921
|
+
const localSnapshot = local.map((c) => ({
|
|
922
|
+
origin: c.origin.slice(),
|
|
923
|
+
scale: c.scale.slice(),
|
|
924
|
+
angles: c.angles.slice()
|
|
925
|
+
}));
|
|
882
926
|
for (let pass = 0; pass < 8; pass++) {
|
|
883
927
|
let changed = false;
|
|
884
928
|
for (const c of local) {
|
|
@@ -892,20 +936,11 @@ function parseScene(sceneJson, project) {
|
|
|
892
936
|
const pr = objects[pIdx];
|
|
893
937
|
const prs = pr.scale;
|
|
894
938
|
const runtimeBound = prs !== null && typeof prs === "object" && (typeof prs.script === "string" || prs.user !== void 0);
|
|
895
|
-
const
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const ox = c.origin[0] * pscale[0];
|
|
901
|
-
const oy = c.origin[1] * pscale[1];
|
|
902
|
-
c.origin[0] = pc.origin[0] + ox * cos - oy * sin;
|
|
903
|
-
c.origin[1] = pc.origin[1] + ox * sin + oy * cos;
|
|
904
|
-
c.origin[2] = pc.origin[2] + c.origin[2];
|
|
905
|
-
c.angles[2] = pc.angles[2] + c.angles[2];
|
|
906
|
-
c.scale[0] = pscale[0] * c.scale[0];
|
|
907
|
-
c.scale[1] = pscale[1] * c.scale[1];
|
|
908
|
-
c.scale[2] = pscale[2] * c.scale[2];
|
|
939
|
+
const propagateScale = !(runtimeBound && isRenderInert(pr));
|
|
940
|
+
const w = composeChildTransform(pc, c, propagateScale);
|
|
941
|
+
c.origin = w.origin;
|
|
942
|
+
c.scale = w.scale;
|
|
943
|
+
c.angles = w.angles;
|
|
909
944
|
c.parent = null;
|
|
910
945
|
changed = true;
|
|
911
946
|
}
|
|
@@ -1125,6 +1160,18 @@ function parseScene(sceneJson, project) {
|
|
|
1125
1160
|
origin: layerOrigin,
|
|
1126
1161
|
scale: world.scale,
|
|
1127
1162
|
angles: world.angles,
|
|
1163
|
+
// [we-scene patch] 父级相对变换(WE 场景图的真实语义)。origin/scale/angles
|
|
1164
|
+
// 上的脚本与关键帧动画一律在这层空间收发,再由 recomposeWorld 合成回上面的
|
|
1165
|
+
// world 三件套。渲染 / hittest / getTransformMatrix 仍只读 world,不受影响。
|
|
1166
|
+
// isPostProcess 层的 world 被强制成整幅画布,local 对它无意义(recompose 跳过)。
|
|
1167
|
+
localOrigin: localSnapshot[i].origin,
|
|
1168
|
+
localScale: localSnapshot[i].scale,
|
|
1169
|
+
localAngles: localSnapshot[i].angles,
|
|
1170
|
+
// 「渲染惰性纯容器」:父 scale 是否传给子层由父级这个标志决定,
|
|
1171
|
+
// 判据与 parse 合并阶段逐字相同(见 isRenderInert)。
|
|
1172
|
+
renderInert: isRenderInert(o),
|
|
1173
|
+
// 父 scale 绑了脚本/用户属性(运行时可变)。与 renderInert 一起决定传播闸门。
|
|
1174
|
+
scaleRuntimeBound: !!(o.scale !== null && typeof o.scale === "object" && (typeof o.scale.script === "string" || o.scale.user !== void 0)),
|
|
1128
1175
|
size: layerSize,
|
|
1129
1176
|
alignment: o.alignment || "center",
|
|
1130
1177
|
color: parseColor(o.color),
|
|
@@ -1235,15 +1282,110 @@ function resolveMaterial(modelJson) {
|
|
|
1235
1282
|
cropoffset: modelJson.cropoffset ? parseVec2(modelJson.cropoffset) : null
|
|
1236
1283
|
};
|
|
1237
1284
|
}
|
|
1285
|
+
function recomposeWorld(layers, dirty) {
|
|
1286
|
+
if (!layers || layers.length === 0) return;
|
|
1287
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1288
|
+
for (const l of layers) {
|
|
1289
|
+
if (l && l.id !== void 0 && l.id !== null) byId.set(l.id, l);
|
|
1290
|
+
}
|
|
1291
|
+
const depthOf = (l) => {
|
|
1292
|
+
let d = 0;
|
|
1293
|
+
let p = l.parentId;
|
|
1294
|
+
for (let guard = 0; p !== void 0 && p !== null && guard < 64; guard++) {
|
|
1295
|
+
const parent = byId.get(p);
|
|
1296
|
+
if (!parent) break;
|
|
1297
|
+
d++;
|
|
1298
|
+
p = parent.parentId;
|
|
1299
|
+
}
|
|
1300
|
+
return d;
|
|
1301
|
+
};
|
|
1302
|
+
const targets = [];
|
|
1303
|
+
for (const l of layers) {
|
|
1304
|
+
if (!l || !l.localOrigin) continue;
|
|
1305
|
+
if (l.isPostProcess) continue;
|
|
1306
|
+
if (dirty && !dirty.has(l.id)) continue;
|
|
1307
|
+
targets.push(l);
|
|
1308
|
+
}
|
|
1309
|
+
targets.sort((a, b) => depthOf(a) - depthOf(b));
|
|
1310
|
+
for (const l of targets) {
|
|
1311
|
+
const parent = l.parentId !== void 0 && l.parentId !== null ? byId.get(l.parentId) : null;
|
|
1312
|
+
let w;
|
|
1313
|
+
if (!parent) {
|
|
1314
|
+
w = { origin: l.localOrigin.slice(), scale: l.localScale.slice(), angles: l.localAngles.slice() };
|
|
1315
|
+
} else {
|
|
1316
|
+
const propagateScale = !(parent.scaleRuntimeBound && parent.renderInert);
|
|
1317
|
+
w = composeChildTransform(
|
|
1318
|
+
{ origin: parent.origin, scale: parent.scale, angles: parent.angles },
|
|
1319
|
+
{ origin: l.localOrigin, scale: l.localScale, angles: l.localAngles },
|
|
1320
|
+
propagateScale
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
const d = l.attachBindDelta;
|
|
1324
|
+
if (d) {
|
|
1325
|
+
w.origin[0] += d[0];
|
|
1326
|
+
w.origin[1] += d[1];
|
|
1327
|
+
}
|
|
1328
|
+
l.origin[0] = w.origin[0];
|
|
1329
|
+
l.origin[1] = w.origin[1];
|
|
1330
|
+
l.origin[2] = w.origin[2];
|
|
1331
|
+
l.scale[0] = w.scale[0];
|
|
1332
|
+
l.scale[1] = w.scale[1];
|
|
1333
|
+
l.scale[2] = w.scale[2];
|
|
1334
|
+
l.angles[0] = w.angles[0];
|
|
1335
|
+
l.angles[1] = w.angles[1];
|
|
1336
|
+
l.angles[2] = w.angles[2];
|
|
1337
|
+
if (l.attachBase) {
|
|
1338
|
+
l.attachBase[0] = w.origin[0];
|
|
1339
|
+
l.attachBase[1] = w.origin[1];
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
function collectTransformDirty(layers, extraSeeds) {
|
|
1344
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
1345
|
+
if (!layers || layers.length === 0) return dirty;
|
|
1346
|
+
const childrenOf = /* @__PURE__ */ new Map();
|
|
1347
|
+
for (const l of layers) {
|
|
1348
|
+
if (!l || l.parentId === void 0 || l.parentId === null) continue;
|
|
1349
|
+
const list = childrenOf.get(l.parentId);
|
|
1350
|
+
if (list) list.push(l);
|
|
1351
|
+
else childrenOf.set(l.parentId, [l]);
|
|
1352
|
+
}
|
|
1353
|
+
const TRANSFORM_FIELDS = ["origin", "scale", "angles"];
|
|
1354
|
+
const seeds = [];
|
|
1355
|
+
for (const l of layers) {
|
|
1356
|
+
if (!l || l.id === void 0 || l.id === null) continue;
|
|
1357
|
+
const scripts = l.objectScripts || null;
|
|
1358
|
+
const anims = l.objectAnimations || null;
|
|
1359
|
+
const bound = TRANSFORM_FIELDS.some((f) => scripts && scripts[f] || anims && anims[f]);
|
|
1360
|
+
if (bound) seeds.push(l);
|
|
1361
|
+
}
|
|
1362
|
+
if (extraSeeds) {
|
|
1363
|
+
for (const l of extraSeeds) if (l && l.id !== void 0 && l.id !== null) seeds.push(l);
|
|
1364
|
+
}
|
|
1365
|
+
const stack = seeds.slice();
|
|
1366
|
+
for (let guard = 0; stack.length > 0 && guard < 1e5; guard++) {
|
|
1367
|
+
const l = stack.pop();
|
|
1368
|
+
if (!l || l.id === void 0 || l.id === null) continue;
|
|
1369
|
+
if (dirty.has(l.id)) continue;
|
|
1370
|
+
dirty.add(l.id);
|
|
1371
|
+
const kids = childrenOf.get(l.id);
|
|
1372
|
+
if (kids) for (const c of kids) stack.push(c);
|
|
1373
|
+
}
|
|
1374
|
+
return dirty;
|
|
1375
|
+
}
|
|
1238
1376
|
const sceneMod = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1239
1377
|
__proto__: null,
|
|
1240
1378
|
applySolidFromModel,
|
|
1379
|
+
collectTransformDirty,
|
|
1380
|
+
composeChildTransform,
|
|
1381
|
+
isRenderInert,
|
|
1241
1382
|
parseBool,
|
|
1242
1383
|
parseColor,
|
|
1243
1384
|
parseNum,
|
|
1244
1385
|
parseScene,
|
|
1245
1386
|
parseVec2,
|
|
1246
1387
|
parseVec3,
|
|
1388
|
+
recomposeWorld,
|
|
1247
1389
|
recomputeLayerVisibility,
|
|
1248
1390
|
resolveMaterial
|
|
1249
1391
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -1647,12 +1789,36 @@ function expandMacrosIn(text, depth) {
|
|
|
1647
1789
|
const { defs, fns } = collectMacros(text);
|
|
1648
1790
|
if (defs.size === 0 && fns.size === 0) break;
|
|
1649
1791
|
const lines = text.split("\n");
|
|
1792
|
+
const defLine = /* @__PURE__ */ new Map();
|
|
1793
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1794
|
+
const dm = /^[ \t]*#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)/.exec(lines[i]);
|
|
1795
|
+
if (dm && !defLine.has(dm[1])) defLine.set(dm[1], i);
|
|
1796
|
+
}
|
|
1797
|
+
const declLine = /* @__PURE__ */ new Map();
|
|
1798
|
+
{
|
|
1799
|
+
const TYPES = "(?:float|int|bool|vec[234]|ivec[234]|bvec[234]|mat[234])";
|
|
1800
|
+
for (const name of defs.keys()) {
|
|
1801
|
+
const esc = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1802
|
+
const re = new RegExp(
|
|
1803
|
+
"^\\s*(?:const\\s+|uniform\\s+|varying\\s+|in\\s+|out\\s+|attribute\\s+)*" + TYPES + "\\s+" + esc + "\\s*[=;]"
|
|
1804
|
+
);
|
|
1805
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1806
|
+
if (re.test(lines[i])) {
|
|
1807
|
+
declLine.set(name, i);
|
|
1808
|
+
break;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1650
1813
|
let changed = false;
|
|
1651
1814
|
for (let i = 0; i < lines.length; i++) {
|
|
1652
1815
|
const line = lines[i];
|
|
1653
1816
|
if (/^[ \t]*#/.test(line)) continue;
|
|
1654
1817
|
let l = line;
|
|
1655
1818
|
for (const [name, val] of defs) {
|
|
1819
|
+
const dl = defLine.get(name);
|
|
1820
|
+
if (dl !== void 0 && i < dl) continue;
|
|
1821
|
+
if (declLine.get(name) === i) continue;
|
|
1656
1822
|
const re = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
1657
1823
|
if (re.test(l)) {
|
|
1658
1824
|
l = replaceWord(l, name, val);
|
|
@@ -1660,6 +1826,8 @@ function expandMacrosIn(text, depth) {
|
|
|
1660
1826
|
}
|
|
1661
1827
|
}
|
|
1662
1828
|
for (const [name, info] of fns) {
|
|
1829
|
+
const dl = defLine.get(name);
|
|
1830
|
+
if (dl !== void 0 && i < dl) continue;
|
|
1663
1831
|
if (l.includes(name)) {
|
|
1664
1832
|
l = expandFunctionMacro(l, name, info, depth);
|
|
1665
1833
|
changed = true;
|
|
@@ -1934,6 +2102,13 @@ function isDeclaration(text, idx) {
|
|
|
1934
2102
|
const word = text.slice(p + 1, e);
|
|
1935
2103
|
return GLSL_TYPES.has(word);
|
|
1936
2104
|
}
|
|
2105
|
+
function collectIntNames(code) {
|
|
2106
|
+
const names = /* @__PURE__ */ new Set();
|
|
2107
|
+
let m;
|
|
2108
|
+
const declRe = /\b(?:const\s+)?int\s+([A-Za-z_]\w*)\s*[=;)\u0003]/g;
|
|
2109
|
+
while ((m = declRe.exec(code)) !== null) names.add(m[1]);
|
|
2110
|
+
return names;
|
|
2111
|
+
}
|
|
1937
2112
|
function rewriteCall(text, callName, fn) {
|
|
1938
2113
|
let out = "";
|
|
1939
2114
|
let i = 0;
|
|
@@ -2018,23 +2193,73 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2018
2193
|
const dim = sw.length;
|
|
2019
2194
|
return fn + "(vec" + dim + "(" + num2 + "), " + expr + ")";
|
|
2020
2195
|
});
|
|
2021
|
-
code = code.replace(
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
code = code.replace(/([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))\s*([+-])\s*(\d+)(?![\d.])/g, "$1 $2 $3.0");
|
|
2027
|
-
code = code.replace(/(^|[^\w.])(\d+)\s*([+-])\s*(\d+\.\d+)/g, "$1$2.0 $3 $4");
|
|
2028
|
-
code = code.replace(/(^|[^\w.])(\d+)\s*([+-])\s*([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))/g, "$1$2.0 $3 $4");
|
|
2029
|
-
{
|
|
2030
|
-
const floatNames = /* @__PURE__ */ new Set();
|
|
2031
|
-
const declRe = /\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
2032
|
-
let dm;
|
|
2033
|
-
while ((dm = declRe.exec(code)) !== null) floatNames.add(dm[1]);
|
|
2034
|
-
if (floatNames.size > 0) {
|
|
2035
|
-
const alt = Array.from(floatNames).sort((a, b) => b.length - a.length).join("|");
|
|
2036
|
-
code = code.replace(new RegExp("(^|[^\\w.])(\\d+)\\s*([+-])\\s*(" + alt + ")(?![A-Za-z0-9_])", "g"), "$1$2.0 $3 $4");
|
|
2196
|
+
code = code.replace(
|
|
2197
|
+
/(\.([xyzwrgba]{2,4})\s*=\s*)(max|min)\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*,\s*([^;]+?)\s*\)\s*;/g,
|
|
2198
|
+
(all, lead, sw, fn, scalar, vecExpr) => {
|
|
2199
|
+
if (!/\.[xyzwrgba]{2,4}\b|\bvec[234]\s*\(/.test(vecExpr)) return all;
|
|
2200
|
+
return `${lead}${fn}(vec${sw.length}(${scalar}), ${vecExpr});`;
|
|
2037
2201
|
}
|
|
2202
|
+
);
|
|
2203
|
+
code = code.replace(
|
|
2204
|
+
/(^|[^\w)\]])([+-])([+-])(?=[\d.])/g,
|
|
2205
|
+
(all, pre, s1, s2) => pre + (s1 === s2 ? "+" : "-")
|
|
2206
|
+
);
|
|
2207
|
+
const sciHoles = [];
|
|
2208
|
+
code = code.replace(/\b\d+(?:\.\d+)?[eE][+-]?\d+\b/g, (m) => {
|
|
2209
|
+
sciHoles.push(m);
|
|
2210
|
+
return "" + "".repeat(sciHoles.length) + "";
|
|
2211
|
+
});
|
|
2212
|
+
const forHoles = [];
|
|
2213
|
+
code = code.replace(/\bfor\s*\(\s*int\s+([A-Za-z_]\w*)([^)]*)\)/g, (m, name, rest) => {
|
|
2214
|
+
forHoles.push(rest + ")");
|
|
2215
|
+
return `for (int ${name}${"".repeat(forHoles.length)}`;
|
|
2216
|
+
});
|
|
2217
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
2218
|
+
const before = code;
|
|
2219
|
+
code = code.replace(/(^|[^\w.])(\d+)\s*([*/])\s*([A-Za-z_][A-Za-z0-9_]*)/g, "$1$2.0 $3 $4");
|
|
2220
|
+
code = code.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\s*([*/])\s*(\d+)(?![\d.])/g, "$1 $2 $3.0");
|
|
2221
|
+
code = code.replace(/(\d+\.\d+)\s*([*/])\s*(\d+)(?![\d.])/g, "$1 $2 $3.0");
|
|
2222
|
+
code = code.replace(/(^|[^\w.])(\d+)\s*([*/])\s*(\d+\.\d+)/g, "$1$2.0 $3 $4");
|
|
2223
|
+
code = code.replace(/(\.\d+)\s*([+-])\s*(\d+)(?![\d.])/g, "$1 $2 $3.0");
|
|
2224
|
+
code = code.replace(/([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))\s*([+-])\s*(\d+)(?![\d.])/g, "$1 $2 $3.0");
|
|
2225
|
+
code = code.replace(/(^|[^\w.])(\d+)\s*([+-])\s*(\d+\.\d+)/g, "$1$2.0 $3 $4");
|
|
2226
|
+
code = code.replace(/(^|[^\w.])(\d+)\s*([+-])\s*([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))/g, "$1$2.0 $3 $4");
|
|
2227
|
+
code = code.replace(
|
|
2228
|
+
/(^|[^\w.])(\d+)\s*([*/+-])\s*(\()/g,
|
|
2229
|
+
(all, pre, num2, op, open, offset, whole) => {
|
|
2230
|
+
let depth = 0;
|
|
2231
|
+
let end = offset + all.length - 1;
|
|
2232
|
+
for (; end < whole.length; end++) {
|
|
2233
|
+
const ch = whole[end];
|
|
2234
|
+
if (ch === "(") depth++;
|
|
2235
|
+
else if (ch === ")") {
|
|
2236
|
+
depth--;
|
|
2237
|
+
if (depth === 0) {
|
|
2238
|
+
end++;
|
|
2239
|
+
break;
|
|
2240
|
+
}
|
|
2241
|
+
} else if (depth === 0 && (ch === ";" || ch === "," || ch === "\n")) break;
|
|
2242
|
+
}
|
|
2243
|
+
for (; end < whole.length; end++) {
|
|
2244
|
+
const ch = whole[end];
|
|
2245
|
+
if (ch === ";" || ch === "," || ch === "\n" || ch === ")") break;
|
|
2246
|
+
}
|
|
2247
|
+
const seg = whole.slice(offset, end);
|
|
2248
|
+
return /\d\.\d/.test(seg) ? `${pre}${num2}.0 ${op} ${open}` : all;
|
|
2249
|
+
}
|
|
2250
|
+
);
|
|
2251
|
+
{
|
|
2252
|
+
const floatNames = /* @__PURE__ */ new Set();
|
|
2253
|
+
const declRe = /\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
2254
|
+
let dm;
|
|
2255
|
+
while ((dm = declRe.exec(code)) !== null) floatNames.add(dm[1]);
|
|
2256
|
+
if (floatNames.size > 0) {
|
|
2257
|
+
const alt = Array.from(floatNames).sort((a, b) => b.length - a.length).join("|");
|
|
2258
|
+
code = code.replace(new RegExp("(^|[^\\w.])(\\d+)\\s*([+-])\\s*(" + alt + ")(?![A-Za-z0-9_])", "g"), "$1$2.0 $3 $4");
|
|
2259
|
+
code = code.replace(new RegExp("\\b(" + alt + ")\\s*([+-])\\s*(\\d+)(?![\\d.])", "g"), "$1 $2 $3.0");
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
if (code === before) break;
|
|
2038
2263
|
}
|
|
2039
2264
|
{
|
|
2040
2265
|
const FLOAT_BUILTINS = [
|
|
@@ -2170,6 +2395,67 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2170
2395
|
return pre + lhs + " = " + rhs + "." + SW[lw] + ";";
|
|
2171
2396
|
});
|
|
2172
2397
|
}
|
|
2398
|
+
{
|
|
2399
|
+
const floatDecl = /* @__PURE__ */ new Set();
|
|
2400
|
+
{
|
|
2401
|
+
const fdre = /\b(?:uniform|varying|attribute|in|out|const)?\s*\bfloat\s+([A-Za-z_]\w*)/g;
|
|
2402
|
+
let fd;
|
|
2403
|
+
while ((fd = fdre.exec(code)) !== null) floatDecl.add(fd[1]);
|
|
2404
|
+
}
|
|
2405
|
+
const vecW = (expr) => {
|
|
2406
|
+
const e = expr.trim();
|
|
2407
|
+
{
|
|
2408
|
+
const c = /^vec([234])\s*\(/.exec(e);
|
|
2409
|
+
if (c) {
|
|
2410
|
+
let depth = 0;
|
|
2411
|
+
for (let i = e.indexOf("("); i < e.length; i++) {
|
|
2412
|
+
if (e[i] === "(") depth++;
|
|
2413
|
+
else if (e[i] === ")") {
|
|
2414
|
+
depth--;
|
|
2415
|
+
if (depth === 0) return i === e.length - 1 ? Number(c[1]) : 0;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return 0;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
if (/^texture(?:Lod)?\s*\(/.test(e)) {
|
|
2422
|
+
let depth = 0;
|
|
2423
|
+
for (let i = e.indexOf("("); i < e.length; i++) {
|
|
2424
|
+
if (e[i] === "(") depth++;
|
|
2425
|
+
else if (e[i] === ")") {
|
|
2426
|
+
depth--;
|
|
2427
|
+
if (depth === 0) return i === e.length - 1 ? 4 : 0;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
return 0;
|
|
2431
|
+
}
|
|
2432
|
+
const m = /^([A-Za-z_]\w*)(?:\.([xyzwrgba]{2,4}))?\s*[*/]\s*([^*/]+)$/.exec(e);
|
|
2433
|
+
if (!m) return 0;
|
|
2434
|
+
const rhsPart = m[3];
|
|
2435
|
+
if (/\bvec[234]\s*\(|\.[xyzwrgba]{2,4}\b/.test(rhsPart)) return 0;
|
|
2436
|
+
if (m[2]) return m[2].length;
|
|
2437
|
+
if (floatDecl.has(m[1])) return 0;
|
|
2438
|
+
return width.get(m[1]) || 0;
|
|
2439
|
+
};
|
|
2440
|
+
code = code.replace(
|
|
2441
|
+
/(^|[;{}\n]\s*)float\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,
|
|
2442
|
+
(all, pre, name, rhs) => {
|
|
2443
|
+
const w = vecW(rhs);
|
|
2444
|
+
if (w < 2) return all;
|
|
2445
|
+
return `${pre}float ${name} = (${rhs.trim()}).x;`;
|
|
2446
|
+
}
|
|
2447
|
+
);
|
|
2448
|
+
const SWN = { 2: "xy", 3: "xyz" };
|
|
2449
|
+
code = code.replace(
|
|
2450
|
+
/(^|[;{}\n]\s*)vec([23])\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,
|
|
2451
|
+
(all, pre, dim, name, rhs) => {
|
|
2452
|
+
const lw = Number(dim);
|
|
2453
|
+
const rw = vecW(rhs);
|
|
2454
|
+
if (rw <= lw) return all;
|
|
2455
|
+
return `${pre}vec${dim} ${name} = (${rhs.trim()}).${SWN[lw]};`;
|
|
2456
|
+
}
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2173
2459
|
if (width.size > 0) {
|
|
2174
2460
|
const floatNames = /* @__PURE__ */ new Set();
|
|
2175
2461
|
const fre = /\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;
|
|
@@ -2211,6 +2497,7 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2211
2497
|
code = code.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([^;]+);/g, (all, pre, lhs, rhs) => {
|
|
2212
2498
|
const lw = width.get(lhs);
|
|
2213
2499
|
if (!lw) return all;
|
|
2500
|
+
if (floatNames.has(lhs)) return all;
|
|
2214
2501
|
const r = rhs.trim();
|
|
2215
2502
|
if (new RegExp("^vec" + lw + "\\s*\\(").test(r)) return all;
|
|
2216
2503
|
if (width.has(r)) return all;
|
|
@@ -2254,6 +2541,52 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2254
2541
|
new RegExp(`\\bint\\s+([A-Za-z_]\\w*)\\s*=\\s*((?:${FLOAT_FNS})\\s*\\()`, "g"),
|
|
2255
2542
|
"float $1 = $2"
|
|
2256
2543
|
);
|
|
2544
|
+
code = code.replace(
|
|
2545
|
+
/\bfloat\s+([A-Za-z_]\w*)\s*=\s*(int\s*\([^;]*\))\s*;/g,
|
|
2546
|
+
"float $1 = float($2);"
|
|
2547
|
+
);
|
|
2548
|
+
{
|
|
2549
|
+
const intNames = collectIntNames(code);
|
|
2550
|
+
if (intNames.size > 0) {
|
|
2551
|
+
code = code.replace(
|
|
2552
|
+
/\b(const\s+)?float\s+([A-Za-z_]\w*)\s*=\s*([^;{}]+);/g,
|
|
2553
|
+
(all, cst, name, rhs) => {
|
|
2554
|
+
const body = rhs.trim();
|
|
2555
|
+
if (/\./.test(body)) return all;
|
|
2556
|
+
if (/[A-Za-z_]\w*\s*\(/.test(body)) return all;
|
|
2557
|
+
const ids = body.match(/[A-Za-z_]\w*/g);
|
|
2558
|
+
if (!ids || !ids.length) return all;
|
|
2559
|
+
if (!ids.every((x) => intNames.has(x))) return all;
|
|
2560
|
+
return `${cst || ""}float ${name} = float(${body});`;
|
|
2561
|
+
}
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
{
|
|
2566
|
+
const intNames = collectIntNames(code);
|
|
2567
|
+
const floatNames = /* @__PURE__ */ new Set();
|
|
2568
|
+
let fm;
|
|
2569
|
+
const fDeclRe = /\b(?:const\s+|uniform\s+|varying\s+|in\s+|out\s+)*float\s+([A-Za-z_]\w*)/g;
|
|
2570
|
+
while ((fm = fDeclRe.exec(code)) !== null) floatNames.add(fm[1]);
|
|
2571
|
+
for (const n of [...intNames]) {
|
|
2572
|
+
if (floatNames.has(n)) {
|
|
2573
|
+
intNames.delete(n);
|
|
2574
|
+
floatNames.delete(n);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
if (intNames.size > 0 && floatNames.size > 0) {
|
|
2578
|
+
const iAlt = [...intNames].sort((a, b) => b.length - a.length).join("|");
|
|
2579
|
+
const fAlt = [...floatNames].sort((a, b) => b.length - a.length).join("|");
|
|
2580
|
+
code = code.replace(
|
|
2581
|
+
new RegExp(`\\b(${iAlt})\\s*([*/+-])\\s*(${fAlt})\\b`, "g"),
|
|
2582
|
+
(all, a, op, b) => `float(${a}) ${op} ${b}`
|
|
2583
|
+
);
|
|
2584
|
+
code = code.replace(
|
|
2585
|
+
new RegExp(`\\b(${fAlt})\\s*([*/+-])\\s*(${iAlt})\\b`, "g"),
|
|
2586
|
+
(all, a, op, b) => `${a} ${op} float(${b})`
|
|
2587
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2257
2590
|
{
|
|
2258
2591
|
const boolNames = /* @__PURE__ */ new Set();
|
|
2259
2592
|
const boolRe = /\bbool\s+([A-Za-z_]\w*)\s*=/g;
|
|
@@ -2267,6 +2600,17 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2267
2600
|
);
|
|
2268
2601
|
}
|
|
2269
2602
|
}
|
|
2603
|
+
{
|
|
2604
|
+
const CMP = /\(\s*([^()&|]+?)\s*(<=|>=|<|>|==|!=)\s*([^()&|]+?)\s*\)/g;
|
|
2605
|
+
code = code.replace(
|
|
2606
|
+
new RegExp(CMP.source + "\\s*([*/])", "g"),
|
|
2607
|
+
(all, lhs, op, rhs, mulOp) => `float(${lhs.trim()} ${op} ${rhs.trim()}) ${mulOp}`
|
|
2608
|
+
);
|
|
2609
|
+
code = code.replace(
|
|
2610
|
+
new RegExp("([-+*/]=\\s*)" + CMP.source, "g"),
|
|
2611
|
+
(all, assign, lhs, op, rhs) => `${assign}float(${lhs.trim()} ${op} ${rhs.trim()})`
|
|
2612
|
+
);
|
|
2613
|
+
}
|
|
2270
2614
|
{
|
|
2271
2615
|
const names = /* @__PURE__ */ new Set();
|
|
2272
2616
|
for (const fm of code.matchAll(/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?float\s+([A-Za-z_]\w*)\s*\[/g)) {
|
|
@@ -2285,6 +2629,17 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2285
2629
|
let p = close1 + 1;
|
|
2286
2630
|
while (p < code.length && /[ \t]/.test(code[p])) p++;
|
|
2287
2631
|
if (code[p] !== "[") {
|
|
2632
|
+
const e12 = code.slice(open1 + 1, close1);
|
|
2633
|
+
const t = e12.trim();
|
|
2634
|
+
const isFloatish = /\d\.\d/.test(t) || /^[A-Za-z_]\w*$/.test(t) && new RegExp("\\bfloat\\s+" + t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b").test(code);
|
|
2635
|
+
const alreadyInt = /^\s*int\s*\(/.test(t) || /^-?\d+$/.test(t);
|
|
2636
|
+
if (isFloatish && !alreadyInt) {
|
|
2637
|
+
out += code.slice(last, fm.index);
|
|
2638
|
+
out += fm[1] + "[int(" + t + ")]";
|
|
2639
|
+
last = close1 + 1;
|
|
2640
|
+
re.lastIndex = last;
|
|
2641
|
+
continue;
|
|
2642
|
+
}
|
|
2288
2643
|
re.lastIndex = close1 + 1;
|
|
2289
2644
|
continue;
|
|
2290
2645
|
}
|
|
@@ -2425,6 +2780,20 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2425
2780
|
}).join("\n");
|
|
2426
2781
|
}
|
|
2427
2782
|
}
|
|
2783
|
+
code = code.replace(
|
|
2784
|
+
/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,
|
|
2785
|
+
(all, pre, ty, sp, name, tail) => {
|
|
2786
|
+
const vt = vertTypes.get(name);
|
|
2787
|
+
if (!vt || RANK[vt] >= RANK[ty]) return all;
|
|
2788
|
+
const CH = "xyzw";
|
|
2789
|
+
const RG = "rgba";
|
|
2790
|
+
const over = new RegExp(
|
|
2791
|
+
"\\b" + name + "\\s*\\.\\s*[" + CH + RG + "]*[" + CH.slice(RANK[vt]) + RG.slice(RANK[vt]) + "]"
|
|
2792
|
+
);
|
|
2793
|
+
if (over.test(code)) return all;
|
|
2794
|
+
return pre + vt + sp + name + tail;
|
|
2795
|
+
}
|
|
2796
|
+
);
|
|
2428
2797
|
}
|
|
2429
2798
|
{
|
|
2430
2799
|
const inVecN = /* @__PURE__ */ new Map();
|
|
@@ -2484,18 +2853,27 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2484
2853
|
let body = code.slice(braceIdx + 1);
|
|
2485
2854
|
const decls = [];
|
|
2486
2855
|
for (const name of written) {
|
|
2856
|
+
const shadowed = new RegExp(
|
|
2857
|
+
"(?:^|[;{}\\n])\\s*(?:highp|mediump|lowp\\s+)?(?:vec[234]|float|int|bool)\\s+" + name + "\\s*[=;]"
|
|
2858
|
+
).test(body);
|
|
2859
|
+
if (shadowed) continue;
|
|
2487
2860
|
const tm = new RegExp("^\\s*in\\s+(?:highp|mediump|lowp\\s+)?(vec[234]|float)\\s+" + name + "\\s*;", "m").exec(code);
|
|
2488
2861
|
const ty = tm ? tm[1] : "vec4";
|
|
2489
2862
|
decls.push(" " + ty + " " + name + "_rw = " + name + ";");
|
|
2490
2863
|
body = replaceWord(body, name, name + "_rw");
|
|
2491
2864
|
}
|
|
2492
|
-
|
|
2865
|
+
if (decls.length > 0) {
|
|
2866
|
+
body = "\n" + decls.map((d) => d.replace(/= (\w+)_rw;/, "= $1;")).join("\n") + "\n" + body;
|
|
2867
|
+
}
|
|
2493
2868
|
code = head + body;
|
|
2494
2869
|
}
|
|
2495
2870
|
}
|
|
2496
2871
|
}
|
|
2497
2872
|
code = code.replace(/\[(?:unroll|loop|branch|flatten)\]\s*/g, "");
|
|
2498
2873
|
code = code.replace(/\bstatic\s+/g, "");
|
|
2874
|
+
if (forHoles.length > 0) {
|
|
2875
|
+
code = code.replace(/\u0003(\u0004+)\u0003/g, (m, marks) => forHoles[marks.length - 1]);
|
|
2876
|
+
}
|
|
2499
2877
|
{
|
|
2500
2878
|
const floatNames = /* @__PURE__ */ new Set();
|
|
2501
2879
|
for (const m of code.matchAll(/\b(?:uniform[ \t]+)?(?:highp|mediump|lowp)?[ \t]*float[ \t]+([A-Za-z_]\w*)[ \t]*[;=]/g)) {
|
|
@@ -2525,6 +2903,9 @@ function hlsl2glsl(src, stage, combos, includeResolver, siblingSrc) {
|
|
|
2525
2903
|
return line;
|
|
2526
2904
|
}).join("\n");
|
|
2527
2905
|
}
|
|
2906
|
+
if (sciHoles.length > 0) {
|
|
2907
|
+
code = code.replace(/\u0001(\u0002+)\u0001/g, (m, marks) => sciHoles[marks.length - 1]);
|
|
2908
|
+
}
|
|
2528
2909
|
let prologue = "#version 300 es\n";
|
|
2529
2910
|
if (stage === "vert") {
|
|
2530
2911
|
prologue += "precision highp float;\n";
|
|
@@ -3340,8 +3721,9 @@ function createRenderer(canvas, opts = {}) {
|
|
|
3340
3721
|
uni.set(base, { loc: gl.getUniformLocation(prog, info.name), type: GL_TYPES[info.type] || "unknown", size: info.size });
|
|
3341
3722
|
}
|
|
3342
3723
|
const matMeta = { ...parseMaterialMeta(src.vert), ...parseMaterialMeta(src.frag) };
|
|
3724
|
+
const ndcDirect = /gl_Position\s*=\s*vec4\s*\(\s*a_Position/.test(src.vert) && !/[aA]_Position[\s\S]{0,40}mul\s*\(/.test(src.vert);
|
|
3343
3725
|
const samplerDefaults = new Map([...parseSamplerDefaults(src.vert), ...parseSamplerDefaults(src.frag)]);
|
|
3344
|
-
const entry = { prog, uni, matMeta, samplerDefaults, fragGlsl, vertGlsl };
|
|
3726
|
+
const entry = { prog, uni, matMeta, samplerDefaults, fragGlsl, vertGlsl, ndcDirect };
|
|
3345
3727
|
progCache.set(key, entry);
|
|
3346
3728
|
return entry;
|
|
3347
3729
|
}
|
|
@@ -4093,7 +4475,13 @@ function createRenderer(canvas, opts = {}) {
|
|
|
4093
4475
|
}
|
|
4094
4476
|
const drawLayers = cam.perspective ? scene.layers.slice().sort((a, b) => Number(!!b.isSkybox) - Number(!!a.isSkybox)) : scene.layers;
|
|
4095
4477
|
for (const layer of drawLayers) {
|
|
4096
|
-
if (
|
|
4478
|
+
if (layer.destroyed) continue;
|
|
4479
|
+
if (!layer.visible) {
|
|
4480
|
+
if (pendingEmptyCompose.has(layer.id)) {
|
|
4481
|
+
captureEmptyComposeAtZOrder(layer, cam, viewProj, width, height);
|
|
4482
|
+
}
|
|
4483
|
+
continue;
|
|
4484
|
+
}
|
|
4097
4485
|
if (layer.isPostProcess && !(layer.effects || []).some((e) => e.visible)) continue;
|
|
4098
4486
|
if (groupChildIds.has(layer.id)) continue;
|
|
4099
4487
|
if (layer.isContainer) {
|
|
@@ -4552,7 +4940,13 @@ function createRenderer(canvas, opts = {}) {
|
|
|
4552
4940
|
gl.bindFramebuffer(gl.FRAMEBUFFER, outFBO.fbo);
|
|
4553
4941
|
gl.viewport(0, 0, outFBO.width, outFBO.height);
|
|
4554
4942
|
gl.bindVertexArray(vao);
|
|
4555
|
-
|
|
4943
|
+
const usePixelQuad = !progEntry.ndcDirect;
|
|
4944
|
+
if (usePixelQuad) {
|
|
4945
|
+
uploadQuad("passPx" + outFBO.width + "x" + outFBO.height, layerQuad(outFBO.width, outFBO.height));
|
|
4946
|
+
} else {
|
|
4947
|
+
uploadQuad("pass", PASS_QUAD);
|
|
4948
|
+
}
|
|
4949
|
+
const passMVP = usePixelQuad ? mat4Transpose(mat4Ortho(0, outFBO.width, 0, outFBO.height, -1e4, 1e4)) : IDENT_M4;
|
|
4556
4950
|
const texNames = mp.textures || [];
|
|
4557
4951
|
const maxTex = Math.max(texNames.length, 8);
|
|
4558
4952
|
const resolutions = /* @__PURE__ */ new Map();
|
|
@@ -4581,7 +4975,7 @@ function createRenderer(canvas, opts = {}) {
|
|
|
4581
4975
|
usedUnits.add(ti);
|
|
4582
4976
|
resolutions.set(ti, [t.width, t.height, t.width, t.height]);
|
|
4583
4977
|
}
|
|
4584
|
-
bindSystemUniforms(uni, layer, time, cam.projW, cam.projH,
|
|
4978
|
+
bindSystemUniforms(uni, layer, time, cam.projW, cam.projH, passMVP, layerOrtho, IDENT_M4, resolutions, layerOrtho, cam);
|
|
4585
4979
|
bindConstants(
|
|
4586
4980
|
uni,
|
|
4587
4981
|
animatedConstants(
|
|
@@ -5088,20 +5482,7 @@ class ParticleSystem {
|
|
|
5088
5482
|
this.model = model || {};
|
|
5089
5483
|
this.override = override || {};
|
|
5090
5484
|
this.layer = layer || null;
|
|
5091
|
-
|
|
5092
|
-
const ls = layer && layer.scale ? layer.scale : [1, 1, 1];
|
|
5093
|
-
const la = layer && layer.angles ? layer.angles : [0, 0, 0];
|
|
5094
|
-
this.originX = lo[0] || 0;
|
|
5095
|
-
this.originY = lo[1] || 0;
|
|
5096
|
-
this.originZ = lo[2] || 0;
|
|
5097
|
-
this.scaleX = ls[0] === 0 ? 1 : ls[0];
|
|
5098
|
-
this.scaleY = ls[1] === 0 ? 1 : ls[1];
|
|
5099
|
-
this.angleZ = (la[2] || 0) * Math.PI / 180;
|
|
5100
|
-
const asx = Math.abs(this.scaleX);
|
|
5101
|
-
const asy = Math.abs(this.scaleY);
|
|
5102
|
-
this.sysScale = Math.min(asx, asy) || 1;
|
|
5103
|
-
this.spriteStretchX = asx / this.sysScale;
|
|
5104
|
-
this.spriteStretchY = asy / this.sysScale;
|
|
5485
|
+
this.syncLayerTransform();
|
|
5105
5486
|
this.maxCount = Math.max(1, Math.min(2e4, num(this.model.maxcount, 100)));
|
|
5106
5487
|
this.simTime = 0;
|
|
5107
5488
|
this.paused = false;
|
|
@@ -5506,6 +5887,31 @@ class ParticleSystem {
|
|
|
5506
5887
|
setVisible(v) {
|
|
5507
5888
|
this.visible = v;
|
|
5508
5889
|
}
|
|
5890
|
+
/**
|
|
5891
|
+
* [we-scene patch] 从图层重新读取变换(构造时也走这里)。
|
|
5892
|
+
*
|
|
5893
|
+
* 发射器变换原先只在构造时缓存一次、之后**从不刷新**。父组一旦带脚本/动画
|
|
5894
|
+
* 变换(全库 17 个粒子层有脚本化祖先),图层被 recomposeWorld 挪走了,
|
|
5895
|
+
* 粒子却仍从旧位置喷出来 —— 画面上是「人物滑走了、他的火焰留在原地」。
|
|
5896
|
+
* 宿主在 recompose 之后对脏子树里的粒子层调用本方法。
|
|
5897
|
+
*/
|
|
5898
|
+
syncLayerTransform() {
|
|
5899
|
+
const layer = this.layer;
|
|
5900
|
+
const lo = layer && layer.origin ? layer.origin : [0, 0, 0];
|
|
5901
|
+
const ls = layer && layer.scale ? layer.scale : [1, 1, 1];
|
|
5902
|
+
const la = layer && layer.angles ? layer.angles : [0, 0, 0];
|
|
5903
|
+
this.originX = lo[0] || 0;
|
|
5904
|
+
this.originY = lo[1] || 0;
|
|
5905
|
+
this.originZ = lo[2] || 0;
|
|
5906
|
+
this.scaleX = ls[0] === 0 ? 1 : ls[0];
|
|
5907
|
+
this.scaleY = ls[1] === 0 ? 1 : ls[1];
|
|
5908
|
+
this.angleZ = (la[2] || 0) * Math.PI / 180;
|
|
5909
|
+
const asx = Math.abs(this.scaleX);
|
|
5910
|
+
const asy = Math.abs(this.scaleY);
|
|
5911
|
+
this.sysScale = Math.min(asx, asy) || 1;
|
|
5912
|
+
this.spriteStretchX = asx / this.sysScale;
|
|
5913
|
+
this.spriteStretchY = asy / this.sysScale;
|
|
5914
|
+
}
|
|
5509
5915
|
// 宿主每帧提供鼠标位置(世界像素);转到局部空间供控制点使用
|
|
5510
5916
|
setPointer(worldX, worldY) {
|
|
5511
5917
|
const dx = worldX - this.originX;
|
|
@@ -7834,6 +8240,7 @@ function applyAttachmentBindOrigins(layers) {
|
|
|
7834
8240
|
for (const c of desc) {
|
|
7835
8241
|
c.parallaxDepth = layer.parallaxDepth ? layer.parallaxDepth.slice() : null;
|
|
7836
8242
|
}
|
|
8243
|
+
layer.attachBindDelta = [d[0], d[1]];
|
|
7837
8244
|
follows.push({
|
|
7838
8245
|
layer,
|
|
7839
8246
|
parent,
|
|
@@ -7848,6 +8255,9 @@ function applyAttachmentBindOrigins(layers) {
|
|
|
7848
8255
|
f.baseY = f.layer.origin[1];
|
|
7849
8256
|
f.subtree = [{ layer: f.layer, x: f.layer.origin[0], y: f.layer.origin[1] }];
|
|
7850
8257
|
for (const c of f.desc) f.subtree.push({ layer: c, x: c.origin[0], y: c.origin[1] });
|
|
8258
|
+
for (const s of f.subtree) {
|
|
8259
|
+
if (!s.layer.attachBase) s.layer.attachBase = [s.x, s.y];
|
|
8260
|
+
}
|
|
7851
8261
|
}
|
|
7852
8262
|
return follows;
|
|
7853
8263
|
}
|
|
@@ -7873,14 +8283,20 @@ function followAttachments(follows, time, getBoneOverrides) {
|
|
|
7873
8283
|
}
|
|
7874
8284
|
deltas.push(parentMeshToWorldDelta(f.parent, cur[12] - f.bindX, cur[13] - f.bindY));
|
|
7875
8285
|
}
|
|
8286
|
+
const baseOf = (s) => {
|
|
8287
|
+
const ab = s.layer.attachBase;
|
|
8288
|
+
if (ab) return ab;
|
|
8289
|
+
return [s.x, s.y];
|
|
8290
|
+
};
|
|
7876
8291
|
const seen = /* @__PURE__ */ new Set();
|
|
7877
8292
|
for (const f of follows) {
|
|
7878
8293
|
const tree = f.subtree || [{ layer: f.layer, x: f.baseX, y: f.baseY }];
|
|
7879
8294
|
for (const s of tree) {
|
|
7880
8295
|
if (seen.has(s.layer)) continue;
|
|
7881
8296
|
seen.add(s.layer);
|
|
7882
|
-
|
|
7883
|
-
s.layer.origin[
|
|
8297
|
+
const b = baseOf(s);
|
|
8298
|
+
s.layer.origin[0] = b[0];
|
|
8299
|
+
s.layer.origin[1] = b[1];
|
|
7884
8300
|
}
|
|
7885
8301
|
}
|
|
7886
8302
|
for (let i = 0; i < follows.length; i++) {
|
|
@@ -8767,6 +9183,19 @@ function evalTextScript(script, scriptprops, opts = {}) {
|
|
|
8767
9183
|
if (opts.onError) opts.onError(e, "applyUserProperties");
|
|
8768
9184
|
}
|
|
8769
9185
|
},
|
|
9186
|
+
/** 直调 update 不做文本加工:层可见性脚本(visible.script)要拿原始返回值
|
|
9187
|
+
* ——布尔控可见,callUpdate 会把它吞成 null(防画到画面上的文字版语义)。 */
|
|
9188
|
+
callUpdateRaw(value) {
|
|
9189
|
+
if (!fns.update || sandbox.disabled) return void 0;
|
|
9190
|
+
try {
|
|
9191
|
+
return fns.update(value);
|
|
9192
|
+
} catch (e) {
|
|
9193
|
+
sandbox.errCount++;
|
|
9194
|
+
if (opts.onError) opts.onError(e, "update");
|
|
9195
|
+
if (sandbox.errCount >= 3) sandbox.disabled = true;
|
|
9196
|
+
return void 0;
|
|
9197
|
+
}
|
|
9198
|
+
},
|
|
8770
9199
|
/** 求值当前文本:返回新文本;undefined/null 保留原值;连续出错 3 次熔断回退静态文本 */
|
|
8771
9200
|
callUpdate(value) {
|
|
8772
9201
|
if (!fns.update || sandbox.disabled) return null;
|
|
@@ -9458,13 +9887,8 @@ function makeObjectLayerProxy(layer, opts) {
|
|
|
9458
9887
|
Object.defineProperty(proxy, key, {
|
|
9459
9888
|
enumerable: true,
|
|
9460
9889
|
get() {
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
store[key].x = a[0] || 0;
|
|
9464
|
-
store[key].y = a[1] || 0;
|
|
9465
|
-
store[key].z = a[2] || 0;
|
|
9466
|
-
}
|
|
9467
|
-
return store[key];
|
|
9890
|
+
const a = layer && Array.isArray(layer[key]) ? layer[key] : null;
|
|
9891
|
+
return makeVec3(a || [0, 0, 0]);
|
|
9468
9892
|
},
|
|
9469
9893
|
set(v) {
|
|
9470
9894
|
const a = normVec(v);
|
|
@@ -9660,7 +10084,8 @@ function evalObjectScript(script, scriptprops, opts = {}) {
|
|
|
9660
10084
|
const hasCursorHook = !!(fns && (fns.cursorClick || fns.cursorEnter || fns.cursorLeave || fns.cursorDown || fns.cursorUp || fns.cursorMove));
|
|
9661
10085
|
const hasMediaHook = !!(fns && MEDIA_CALLBACKS.some((n) => fns[n]));
|
|
9662
10086
|
const hasApplyHook = !!(fns && typeof fns.applyUserProperties === "function");
|
|
9663
|
-
|
|
10087
|
+
const usesEngineClock = /\bengine\s*\.\s*(runtime|frametime)\b/.test(body);
|
|
10088
|
+
if (!fns || !fns.update && !hasCursorHook && !hasMediaHook && !hasApplyHook && !usesEngineClock) return null;
|
|
9664
10089
|
const sandbox = {
|
|
9665
10090
|
engine,
|
|
9666
10091
|
scriptProperties: spValues,
|
|
@@ -9961,7 +10386,7 @@ function createEngineTimers(host = {}, opts = {}) {
|
|
|
9961
10386
|
cancel.handle = state.handle;
|
|
9962
10387
|
return cancel;
|
|
9963
10388
|
}
|
|
9964
|
-
function
|
|
10389
|
+
function clearTimeout2(h) {
|
|
9965
10390
|
if (typeof h === "function") {
|
|
9966
10391
|
h();
|
|
9967
10392
|
return;
|
|
@@ -9982,7 +10407,7 @@ function createEngineTimers(host = {}, opts = {}) {
|
|
|
9982
10407
|
return {
|
|
9983
10408
|
setTimeout,
|
|
9984
10409
|
setInterval: setInterval2,
|
|
9985
|
-
clearTimeout,
|
|
10410
|
+
clearTimeout: clearTimeout2,
|
|
9986
10411
|
clearInterval: clearInterval2,
|
|
9987
10412
|
dispose,
|
|
9988
10413
|
/** 测试与诊断用:尚未触发且未取消的定时器数 */
|
|
@@ -10036,6 +10461,8 @@ function createSimulatedAudio(seed = 20260830) {
|
|
|
10036
10461
|
const BANDS2 = 64;
|
|
10037
10462
|
const rawL = new Float32Array(BANDS2);
|
|
10038
10463
|
const rawR = new Float32Array(BANDS2);
|
|
10464
|
+
const preL64 = new Float32Array(BANDS2);
|
|
10465
|
+
const preR64 = new Float32Array(BANDS2);
|
|
10039
10466
|
const left64 = new Float32Array(BANDS2);
|
|
10040
10467
|
const right64 = new Float32Array(BANDS2);
|
|
10041
10468
|
const left32 = new Float32Array(32);
|
|
@@ -10049,6 +10476,15 @@ function createSimulatedAudio(seed = 20260830) {
|
|
|
10049
10476
|
right32,
|
|
10050
10477
|
left16,
|
|
10051
10478
|
right16,
|
|
10479
|
+
/**
|
|
10480
|
+
* 未钳位(pre-GAIN、pre-clamp)的 64 band,含左右声道 pan。
|
|
10481
|
+
* left64/right64 是 `min(1, v*GAIN)` 之后的值:底鼓段基底就已到 ~0.6、峰值贴 1,
|
|
10482
|
+
* 波峰因数被压平——网页作者按「峰值过阈值」判定敲击时(1520828134 猫爪
|
|
10483
|
+
* `audioArray[i] > 0.5`),事后再乘任何标量都无法把基底与峰值分开。
|
|
10484
|
+
* 网页驱动改对本数组做 gamma 对比扩展,音条墙仍走已标定的 left64/right64。
|
|
10485
|
+
*/
|
|
10486
|
+
preL64,
|
|
10487
|
+
preR64,
|
|
10052
10488
|
/** vumeter:整体响度 0..1(粒子 audioprocessing / 文字脚本 average 用) */
|
|
10053
10489
|
level: 0,
|
|
10054
10490
|
/** 渲染器诊断:当前是否处于「静音段」 */
|
|
@@ -10094,6 +10530,7 @@ function createSimulatedAudio(seed = 20260830) {
|
|
|
10094
10530
|
if (fq >= 0.45) v += hatV * 0.5 * ((fq - 0.45) / 0.55);
|
|
10095
10531
|
v += riser * 0.5;
|
|
10096
10532
|
v *= tilt;
|
|
10533
|
+
const vPre = v;
|
|
10097
10534
|
v = Math.min(1, v * GAIN);
|
|
10098
10535
|
const width = 0.06 + fq * 0.2;
|
|
10099
10536
|
const pan = vnoise(beat * 0.13 + i * 0.35, 11) * width;
|
|
@@ -10102,6 +10539,8 @@ function createSimulatedAudio(seed = 20260830) {
|
|
|
10102
10539
|
const floorV = silent ? 0.012 : 0;
|
|
10103
10540
|
rawL[i] = Math.max(floorV, l);
|
|
10104
10541
|
rawR[i] = Math.max(floorV, r);
|
|
10542
|
+
preL64[i] = Math.max(floorV, Math.max(0, vPre * (1 - pan)));
|
|
10543
|
+
preR64[i] = Math.max(floorV, Math.max(0, vPre * (1 + pan)));
|
|
10105
10544
|
if (i < 48) levelSum += (rawL[i] + rawR[i]) * 0.5;
|
|
10106
10545
|
}
|
|
10107
10546
|
left64.set(rawL);
|
|
@@ -10599,15 +11038,7 @@ function createPointerSource(opts = {}) {
|
|
|
10599
11038
|
state.screenH = v.h || 1;
|
|
10600
11039
|
}
|
|
10601
11040
|
readViewport();
|
|
10602
|
-
function
|
|
10603
|
-
readViewport();
|
|
10604
|
-
let x = ev.clientX;
|
|
10605
|
-
let y = ev.clientY;
|
|
10606
|
-
if (target && typeof target.getBoundingClientRect === "function") {
|
|
10607
|
-
const r = target.getBoundingClientRect();
|
|
10608
|
-
x -= r.left;
|
|
10609
|
-
y -= r.top;
|
|
10610
|
-
}
|
|
11041
|
+
function applyMove(x, y) {
|
|
10611
11042
|
const u = x / state.screenW;
|
|
10612
11043
|
const v = y / state.screenH;
|
|
10613
11044
|
if (!state.has) {
|
|
@@ -10624,18 +11055,35 @@ function createPointerSource(opts = {}) {
|
|
|
10624
11055
|
state.moveCount++;
|
|
10625
11056
|
state.lastEventTime = Date.now();
|
|
10626
11057
|
}
|
|
11058
|
+
function applyButtons(mask) {
|
|
11059
|
+
const left = (mask & 1) !== 0;
|
|
11060
|
+
if (left === state.leftDown) return;
|
|
11061
|
+
state.leftDown = left;
|
|
11062
|
+
if (left) state.downCount++;
|
|
11063
|
+
else state.upCount++;
|
|
11064
|
+
state.lastEventTime = Date.now();
|
|
11065
|
+
}
|
|
11066
|
+
function onMove(ev) {
|
|
11067
|
+
readViewport();
|
|
11068
|
+
let x = ev.clientX;
|
|
11069
|
+
let y = ev.clientY;
|
|
11070
|
+
if (target && typeof target.getBoundingClientRect === "function") {
|
|
11071
|
+
const r = target.getBoundingClientRect();
|
|
11072
|
+
x -= r.left;
|
|
11073
|
+
y -= r.top;
|
|
11074
|
+
}
|
|
11075
|
+
applyMove(x, y);
|
|
11076
|
+
}
|
|
10627
11077
|
function onDown(ev) {
|
|
10628
11078
|
if (ev.button !== void 0 && ev.button !== 0) return;
|
|
10629
|
-
|
|
10630
|
-
state.downCount++;
|
|
11079
|
+
applyButtons(1);
|
|
10631
11080
|
}
|
|
10632
11081
|
function onUp(ev) {
|
|
10633
11082
|
if (ev.button !== void 0 && ev.button !== 0) return;
|
|
10634
|
-
|
|
10635
|
-
state.upCount++;
|
|
11083
|
+
applyButtons(0);
|
|
10636
11084
|
}
|
|
10637
11085
|
function onLeaveWindow() {
|
|
10638
|
-
|
|
11086
|
+
applyButtons(0);
|
|
10639
11087
|
}
|
|
10640
11088
|
let attached = false;
|
|
10641
11089
|
if (target && target.addEventListener) {
|
|
@@ -10650,6 +11098,42 @@ function createPointerSource(opts = {}) {
|
|
|
10650
11098
|
}
|
|
10651
11099
|
return {
|
|
10652
11100
|
state,
|
|
11101
|
+
/**
|
|
11102
|
+
* 外部注入指针状态(宿主轮询系统鼠标后推入)。协议见 docs/INTEGRATION.md。
|
|
11103
|
+
*
|
|
11104
|
+
* 接**归一化**坐标而不是像素:宿主知道自己那块屏的 points 尺寸,除法在它那边
|
|
11105
|
+
* 做更准(混合 DPI 多显示器下无需任何 DPR 折算);这里再乘回 screenW/H 得到
|
|
11106
|
+
* input.cursorScreenPosition 要的像素。
|
|
11107
|
+
*
|
|
11108
|
+
* u/v 是 [0,1]、原点左上、**Y 朝下** —— 与 DOM 路径的 state.u/v 同一空间
|
|
11109
|
+
* (见文件头坐标约定)。宿主不要替 shader 翻 Y。
|
|
11110
|
+
*
|
|
11111
|
+
* 不在这里推进 last:外部推送频率(~90Hz)高于帧率,若在推送里推进 last,
|
|
11112
|
+
* `length(g_PointerPosition - g_PointerPositionLast)` 会恒接近 0,
|
|
11113
|
+
* cursorripple 完全不起波且无报错(与 DOM 路径同一个坑,见文件头)。
|
|
11114
|
+
*
|
|
11115
|
+
* @param {{u:number, v:number, buttons?:number}} p 归一化位置 + 按键位掩码(bit0 左)
|
|
11116
|
+
*/
|
|
11117
|
+
pushExternal(p) {
|
|
11118
|
+
if (!p) return;
|
|
11119
|
+
readViewport();
|
|
11120
|
+
const u = Number(p.u);
|
|
11121
|
+
const v = Number(p.v);
|
|
11122
|
+
if (Number.isFinite(u) && Number.isFinite(v)) {
|
|
11123
|
+
applyMove(u * state.screenW, v * state.screenH);
|
|
11124
|
+
}
|
|
11125
|
+
applyButtons(Number(p.buttons) || 0);
|
|
11126
|
+
},
|
|
11127
|
+
/**
|
|
11128
|
+
* 外部指针离开本窗口(鼠标移到了别的显示器)。
|
|
11129
|
+
*
|
|
11130
|
+
* **只清按键,保留位置与 has** —— 清 has 会让 xray 开窗突然跳到相机外
|
|
11131
|
+
* (renderer.js 的 XRAY_IDLE_SCREEN_UV)、视差弹回中心,画面会明显抽一下。
|
|
11132
|
+
* 语义与 DOM 的 onLeaveWindow 一致:位置停在最后已知点,只是不再按着键。
|
|
11133
|
+
*/
|
|
11134
|
+
pushExternalLeave() {
|
|
11135
|
+
applyButtons(0);
|
|
11136
|
+
},
|
|
10653
11137
|
/**
|
|
10654
11138
|
* 每帧所有消费方读完 current/last **之后**调用一次:把 last 推到 current。
|
|
10655
11139
|
* 事件驱动下 current 在 rAF 之间已被 mousemove 更新;消费前调用会把
|
|
@@ -11176,6 +11660,21 @@ function httpSource(baseUrl, init) {
|
|
|
11176
11660
|
} catch {
|
|
11177
11661
|
return null;
|
|
11178
11662
|
}
|
|
11663
|
+
},
|
|
11664
|
+
async webEntry(signal) {
|
|
11665
|
+
let file = "index.html";
|
|
11666
|
+
try {
|
|
11667
|
+
const r = await fetch(`${base}/project.json`, { ...init, signal });
|
|
11668
|
+
if (r.ok) {
|
|
11669
|
+
const project = await r.json();
|
|
11670
|
+
if (project && typeof project.file === "string" && project.file.trim()) {
|
|
11671
|
+
file = project.file.trim().replace(/^\/+/, "");
|
|
11672
|
+
}
|
|
11673
|
+
}
|
|
11674
|
+
} catch {
|
|
11675
|
+
if (signal?.aborted) throw new Error("aborted");
|
|
11676
|
+
}
|
|
11677
|
+
return { url: `${base}/${file}` };
|
|
11179
11678
|
}
|
|
11180
11679
|
};
|
|
11181
11680
|
}
|
|
@@ -12232,7 +12731,48 @@ const SYSTEM_FONT_FAMILIES = {
|
|
|
12232
12731
|
systemfont_simhei: "SimHei, 'Heiti SC', sans-serif"
|
|
12233
12732
|
};
|
|
12234
12733
|
const fontFaceCache = /* @__PURE__ */ new Map();
|
|
12734
|
+
function fontKeyHash(key) {
|
|
12735
|
+
let h = 5381;
|
|
12736
|
+
for (let i = 0; i < key.length; i++) h = (h << 5) + h + key.charCodeAt(i) | 0;
|
|
12737
|
+
return (h >>> 0).toString(36);
|
|
12738
|
+
}
|
|
12739
|
+
function releaseFontFaces(keys) {
|
|
12740
|
+
for (const key of keys) {
|
|
12741
|
+
const entry = fontFaceCache.get(key);
|
|
12742
|
+
if (!entry) continue;
|
|
12743
|
+
entry.refs--;
|
|
12744
|
+
if (entry.refs > 0) continue;
|
|
12745
|
+
fontFaceCache.delete(key);
|
|
12746
|
+
try {
|
|
12747
|
+
const dead = [];
|
|
12748
|
+
document.fonts.forEach((f) => {
|
|
12749
|
+
if (f.family === entry.family) dead.push(f);
|
|
12750
|
+
});
|
|
12751
|
+
for (const f of dead) document.fonts.delete(f);
|
|
12752
|
+
} catch {
|
|
12753
|
+
}
|
|
12754
|
+
}
|
|
12755
|
+
}
|
|
12235
12756
|
const pkgCache = /* @__PURE__ */ new Map();
|
|
12757
|
+
const PKG_CACHE_MAX_BYTES = 512 * 1024 * 1024;
|
|
12758
|
+
let pkgCacheBytes = 0;
|
|
12759
|
+
function pkgCacheEvict(currentKey) {
|
|
12760
|
+
while (pkgCache.size > 0 && (pkgCache.size > 2 || pkgCacheBytes > PKG_CACHE_MAX_BYTES)) {
|
|
12761
|
+
let oldestKey = null;
|
|
12762
|
+
let oldestAt = Infinity;
|
|
12763
|
+
for (const [k, v] of pkgCache) {
|
|
12764
|
+
if (k === currentKey) continue;
|
|
12765
|
+
if (v.at < oldestAt) {
|
|
12766
|
+
oldestAt = v.at;
|
|
12767
|
+
oldestKey = k;
|
|
12768
|
+
}
|
|
12769
|
+
}
|
|
12770
|
+
if (!oldestKey) break;
|
|
12771
|
+
const victim = pkgCache.get(oldestKey);
|
|
12772
|
+
pkgCacheBytes -= victim.parsed.fileSize || 0;
|
|
12773
|
+
pkgCache.delete(oldestKey);
|
|
12774
|
+
}
|
|
12775
|
+
}
|
|
12236
12776
|
async function loadParsedPkg(rt, cfg, source, signal) {
|
|
12237
12777
|
const cacheKey = source.key;
|
|
12238
12778
|
if (cacheKey) {
|
|
@@ -12255,38 +12795,40 @@ async function loadParsedPkg(rt, cfg, source, signal) {
|
|
|
12255
12795
|
const parsed = pkg.parsePkg(bytes);
|
|
12256
12796
|
if (!cacheKey) return parsed;
|
|
12257
12797
|
pkgCache.set(cacheKey, { parsed, at: Date.now() });
|
|
12258
|
-
|
|
12259
|
-
|
|
12260
|
-
let oldestAt = Infinity;
|
|
12261
|
-
for (const [k, v] of pkgCache) {
|
|
12262
|
-
if (k === cacheKey) continue;
|
|
12263
|
-
if (v.at < oldestAt) {
|
|
12264
|
-
oldestAt = v.at;
|
|
12265
|
-
oldestKey = k;
|
|
12266
|
-
}
|
|
12267
|
-
}
|
|
12268
|
-
if (oldestKey) pkgCache.delete(oldestKey);
|
|
12269
|
-
}
|
|
12798
|
+
pkgCacheBytes += parsed.fileSize || 0;
|
|
12799
|
+
pkgCacheEvict(cacheKey);
|
|
12270
12800
|
return parsed;
|
|
12271
12801
|
}
|
|
12272
12802
|
function mountScene(rt, cfg) {
|
|
12273
12803
|
clear(rt);
|
|
12274
|
-
const c = cfg.canvas ?? document.createElement("canvas");
|
|
12804
|
+
const c = (cfg.canvas instanceof HTMLCanvasElement ? cfg.canvas : null) ?? document.createElement("canvas");
|
|
12275
12805
|
const dpr = effectiveDpr(rt, cfg);
|
|
12276
12806
|
const vw = c.clientWidth || window.innerWidth || 1;
|
|
12277
12807
|
const vh = c.clientHeight || window.innerHeight || 1;
|
|
12278
12808
|
c.width = Math.max(1, Math.round(vw * dpr));
|
|
12279
12809
|
c.height = Math.max(1, Math.round(vh * dpr));
|
|
12280
|
-
if (!cfg.canvas) {
|
|
12810
|
+
if (!(cfg.canvas instanceof HTMLCanvasElement)) {
|
|
12281
12811
|
c.style.cssText = "position:absolute;inset:0;width:100%;height:100%;";
|
|
12282
12812
|
rt.wrap?.appendChild(c);
|
|
12283
12813
|
}
|
|
12284
12814
|
rt.canvas = c;
|
|
12285
12815
|
let disposed = false;
|
|
12816
|
+
const origWarn = console.warn.bind(console);
|
|
12817
|
+
console.warn = (...args) => {
|
|
12818
|
+
const s = args.map((a) => typeof a === "string" ? a : String(a?.message ?? a)).join(" ");
|
|
12819
|
+
if (s.includes("[we-scene]")) {
|
|
12820
|
+
try {
|
|
12821
|
+
reportDiag(rt, cfg, s.slice(0, 300));
|
|
12822
|
+
} catch {
|
|
12823
|
+
}
|
|
12824
|
+
}
|
|
12825
|
+
origWarn(...args);
|
|
12826
|
+
};
|
|
12286
12827
|
const pkgAbort = new AbortController();
|
|
12287
12828
|
let particleCleanup;
|
|
12288
12829
|
rt.sceneCleanup = () => {
|
|
12289
12830
|
disposed = true;
|
|
12831
|
+
console.warn = origWarn;
|
|
12290
12832
|
pkgAbort.abort();
|
|
12291
12833
|
rt.sceneTextUpdate = void 0;
|
|
12292
12834
|
if (particleCleanup) {
|
|
@@ -12343,6 +12885,11 @@ function mountScene(rt, cfg) {
|
|
|
12343
12885
|
const sceneEntry = pkg.getEntry(parsedPkg, "scene.json");
|
|
12344
12886
|
if (!sceneEntry) throw new Error("pkg 中没有 scene.json(不是场景壁纸?)");
|
|
12345
12887
|
const scene = scn.parseScene(JSON.parse(readText(sceneEntry)), project);
|
|
12888
|
+
if (cfg.clearColor) {
|
|
12889
|
+
const g = scene.general ??= {};
|
|
12890
|
+
g.clearcolor = cfg.clearColor;
|
|
12891
|
+
g.clearenabled = true;
|
|
12892
|
+
}
|
|
12346
12893
|
{
|
|
12347
12894
|
const zRaw = scene.general?.zoom;
|
|
12348
12895
|
const zVal = zRaw && typeof zRaw === "object" ? Number(zRaw.value) : Number(zRaw);
|
|
@@ -12441,9 +12988,72 @@ function mountScene(rt, cfg) {
|
|
|
12441
12988
|
level: 0,
|
|
12442
12989
|
silent: true
|
|
12443
12990
|
};
|
|
12991
|
+
const hostAudio = (() => {
|
|
12992
|
+
const snapshot = {
|
|
12993
|
+
left64: zero(64),
|
|
12994
|
+
right64: zero(64),
|
|
12995
|
+
left32: zero(32),
|
|
12996
|
+
right32: zero(32),
|
|
12997
|
+
left16: zero(16),
|
|
12998
|
+
right16: zero(16),
|
|
12999
|
+
// 未钳位频谱:网页驱动会对它做 gamma 对比扩展。宿主给的已是 0..1
|
|
13000
|
+
// 归一化值,没有 pre-GAIN 概念,直接与 left64/right64 共用同一份数据
|
|
13001
|
+
preL64: zero(64),
|
|
13002
|
+
preR64: zero(64),
|
|
13003
|
+
level: 0,
|
|
13004
|
+
silent: true
|
|
13005
|
+
};
|
|
13006
|
+
const down = (dst, src) => {
|
|
13007
|
+
const g = src.length / dst.length;
|
|
13008
|
+
for (let i = 0; i < dst.length; i++) {
|
|
13009
|
+
let s = 0;
|
|
13010
|
+
const i0 = Math.floor(i * g);
|
|
13011
|
+
const i1 = Math.max(i0 + 1, Math.floor((i + 1) * g));
|
|
13012
|
+
for (let j = i0; j < i1; j++) s += src[j];
|
|
13013
|
+
dst[i] = s / (i1 - i0);
|
|
13014
|
+
}
|
|
13015
|
+
};
|
|
13016
|
+
return {
|
|
13017
|
+
active: false,
|
|
13018
|
+
snapshot,
|
|
13019
|
+
/** 每帧从宿主拉一次。宿主返回 null(未采集/无权限)时置 active=false 回落模拟源 */
|
|
13020
|
+
pump() {
|
|
13021
|
+
const src = rt.audioBridge?.();
|
|
13022
|
+
if (!src || !src.left || !src.right) {
|
|
13023
|
+
this.active = false;
|
|
13024
|
+
return;
|
|
13025
|
+
}
|
|
13026
|
+
const n = Math.min(64, src.left.length, src.right.length);
|
|
13027
|
+
let sum = 0;
|
|
13028
|
+
for (let i = 0; i < n; i++) {
|
|
13029
|
+
const l = src.left[i] || 0;
|
|
13030
|
+
const r = src.right[i] || 0;
|
|
13031
|
+
snapshot.left64[i] = l;
|
|
13032
|
+
snapshot.right64[i] = r;
|
|
13033
|
+
snapshot.preL64[i] = l;
|
|
13034
|
+
snapshot.preR64[i] = r;
|
|
13035
|
+
if (i < 48) sum += l;
|
|
13036
|
+
}
|
|
13037
|
+
for (let i = n; i < 64; i++) {
|
|
13038
|
+
snapshot.left64[i] = 0;
|
|
13039
|
+
snapshot.right64[i] = 0;
|
|
13040
|
+
snapshot.preL64[i] = 0;
|
|
13041
|
+
snapshot.preR64[i] = 0;
|
|
13042
|
+
}
|
|
13043
|
+
down(snapshot.left32, snapshot.left64);
|
|
13044
|
+
down(snapshot.right32, snapshot.right64);
|
|
13045
|
+
down(snapshot.left16, snapshot.left64);
|
|
13046
|
+
down(snapshot.right16, snapshot.right64);
|
|
13047
|
+
snapshot.level = Math.min(1, sum / 48);
|
|
13048
|
+
snapshot.silent = snapshot.level < 0.02;
|
|
13049
|
+
this.active = true;
|
|
13050
|
+
}
|
|
13051
|
+
};
|
|
13052
|
+
})();
|
|
13053
|
+
const activeAudioSnapshot = () => hostAudio.active ? hostAudio.snapshot : audioDriverRef.current ? audioDriverRef.current.snapshot : simAudio.snapshot;
|
|
12444
13054
|
renderer.setAudioProvider(() => {
|
|
12445
13055
|
if (!audioSim.enabled) return SILENT_AUDIO;
|
|
12446
|
-
return
|
|
13056
|
+
return activeAudioSnapshot();
|
|
12447
13057
|
});
|
|
12448
13058
|
const audioViews = /* @__PURE__ */ new Map();
|
|
12449
13059
|
window.__audioStats = () => ({
|
|
@@ -12571,6 +13181,10 @@ function mountScene(rt, cfg) {
|
|
|
12571
13181
|
} : {}
|
|
12572
13182
|
);
|
|
12573
13183
|
renderer.setPointerProvider(() => pointerSrc);
|
|
13184
|
+
rt.pointerCtl = {
|
|
13185
|
+
push: (p) => pointerSrc.pushExternal(p),
|
|
13186
|
+
leave: () => pointerSrc.pushExternalLeave()
|
|
13187
|
+
};
|
|
12574
13188
|
{
|
|
12575
13189
|
const prevCleanup = particleCleanup;
|
|
12576
13190
|
particleCleanup = () => {
|
|
@@ -13072,6 +13686,7 @@ function mountScene(rt, cfg) {
|
|
|
13072
13686
|
if (usedVisible && !rt.paused) texEntry.videoCtl.play();
|
|
13073
13687
|
}
|
|
13074
13688
|
const particleSystems = [];
|
|
13689
|
+
const particleDirty = [];
|
|
13075
13690
|
const particleSystemsByLayer = /* @__PURE__ */ new Map();
|
|
13076
13691
|
let builtinTexCount = 0;
|
|
13077
13692
|
const loadParticleTex = async (name) => {
|
|
@@ -13290,7 +13905,10 @@ function mountScene(rt, cfg) {
|
|
|
13290
13905
|
const py = originY != null ? originY : wy;
|
|
13291
13906
|
for (const ps of particleSystems) ps.setPointer(wx, py);
|
|
13292
13907
|
}
|
|
13293
|
-
|
|
13908
|
+
if (particleDirty.length) {
|
|
13909
|
+
for (const ps of particleDirty) ps.syncLayerTransform();
|
|
13910
|
+
}
|
|
13911
|
+
for (const ps of particleSystems) ps.advance(pdt, audioSim.enabled ? activeAudioSnapshot() : null);
|
|
13294
13912
|
if (particleDiagFrame < 2) {
|
|
13295
13913
|
particleDiagFrame++;
|
|
13296
13914
|
if (particleDiagFrame === 2) {
|
|
@@ -13475,6 +14093,17 @@ function mountScene(rt, cfg) {
|
|
|
13475
14093
|
if (attachFollows.length) {
|
|
13476
14094
|
reportDiag(rt, cfg, `attachments: ${attachFollows.length} hanging layers`);
|
|
13477
14095
|
}
|
|
14096
|
+
const transformDirty = scn.collectTransformDirty(
|
|
14097
|
+
scene.layers,
|
|
14098
|
+
attachFollows.map((f) => f.layer)
|
|
14099
|
+
);
|
|
14100
|
+
if (transformDirty.size) {
|
|
14101
|
+
reportDiag(rt, cfg, `transform graph: ${transformDirty.size} live layers`);
|
|
14102
|
+
for (const [lid, list] of particleSystemsByLayer) {
|
|
14103
|
+
if (!transformDirty.has(lid)) continue;
|
|
14104
|
+
for (const ps of list) particleDirty.push(ps);
|
|
14105
|
+
}
|
|
14106
|
+
}
|
|
13478
14107
|
const textWidgets = [];
|
|
13479
14108
|
const textLayerText = /* @__PURE__ */ new Map();
|
|
13480
14109
|
const textShared = {};
|
|
@@ -13488,15 +14117,19 @@ function mountScene(rt, cfg) {
|
|
|
13488
14117
|
const win0 = fitWindow(normalizeFit(rt.cfg.fit), projW, projH, c.width, c.height);
|
|
13489
14118
|
const quality = Math.min(3, Math.max(0.5, c.width / Math.max(1, win0.viewW)));
|
|
13490
14119
|
const fontFamilies = /* @__PURE__ */ new Map();
|
|
14120
|
+
const usedFontKeys = [];
|
|
13491
14121
|
const fontPaths = /* @__PURE__ */ new Set();
|
|
13492
14122
|
for (const l of scene.layers) if (l.isText && l.textFont) fontPaths.add(l.textFont);
|
|
13493
14123
|
for (const e of parsedPkg.entries || []) {
|
|
13494
14124
|
if (typeof e.name === "string" && /^fonts\/.+\.(ttf|otf|woff2?)$/i.test(e.name)) fontPaths.add(e.name);
|
|
13495
14125
|
}
|
|
13496
14126
|
for (const fp of fontPaths) {
|
|
13497
|
-
const
|
|
14127
|
+
const key = `${cfg.src}|${fp}`;
|
|
14128
|
+
const cached = fontFaceCache.get(key);
|
|
13498
14129
|
if (cached) {
|
|
13499
|
-
|
|
14130
|
+
cached.refs++;
|
|
14131
|
+
usedFontKeys.push(key);
|
|
14132
|
+
fontFamilies.set(fp, cached.family);
|
|
13500
14133
|
continue;
|
|
13501
14134
|
}
|
|
13502
14135
|
const sys = SYSTEM_FONT_FAMILIES[fp.toLowerCase()];
|
|
@@ -13510,18 +14143,30 @@ function mountScene(rt, cfg) {
|
|
|
13510
14143
|
const bytes = sanitizeFontForBrowser(
|
|
13511
14144
|
fe instanceof Uint8Array ? fe : new Uint8Array(fe)
|
|
13512
14145
|
);
|
|
13513
|
-
const fam = "wefont_" + fp.split("/").pop().replace(/[^a-zA-Z0-9]/g, "_");
|
|
14146
|
+
const fam = "wefont_" + fontKeyHash(key) + "_" + fp.split("/").pop().replace(/[^a-zA-Z0-9]/g, "_");
|
|
13514
14147
|
const url = URL.createObjectURL(new Blob([bytes]));
|
|
13515
14148
|
const ff = new FontFace(fam, `url(${url})`);
|
|
13516
14149
|
await ff.load();
|
|
14150
|
+
if (disposed) {
|
|
14151
|
+
URL.revokeObjectURL(url);
|
|
14152
|
+
break;
|
|
14153
|
+
}
|
|
13517
14154
|
document.fonts.add(ff);
|
|
13518
14155
|
(rt.objectUrls ??= []).push(url);
|
|
13519
14156
|
fontFamilies.set(fp, fam);
|
|
13520
|
-
fontFaceCache.set(
|
|
14157
|
+
fontFaceCache.set(key, { family: fam, refs: 1 });
|
|
14158
|
+
usedFontKeys.push(key);
|
|
13521
14159
|
} catch (e) {
|
|
13522
14160
|
console.warn(`字体加载失败 ${fp}: ${e.message}`);
|
|
13523
14161
|
}
|
|
13524
14162
|
}
|
|
14163
|
+
if (usedFontKeys.length) {
|
|
14164
|
+
const prevCleanup = rt.sceneCleanup;
|
|
14165
|
+
rt.sceneCleanup = () => {
|
|
14166
|
+
releaseFontFaces(usedFontKeys);
|
|
14167
|
+
prevCleanup?.();
|
|
14168
|
+
};
|
|
14169
|
+
}
|
|
13525
14170
|
textCanvas = document.createElement("canvas");
|
|
13526
14171
|
textCtx = textCanvas.getContext("2d");
|
|
13527
14172
|
const MAX_TEX = 2048;
|
|
@@ -13574,10 +14219,18 @@ function mountScene(rt, cfg) {
|
|
|
13574
14219
|
const hw = layer.size[0] * (layer.scale[0] || 1) / 2;
|
|
13575
14220
|
const hh = layer.size[1] * (layer.scale[1] || 1) / 2;
|
|
13576
14221
|
const a = layer.textAnchor;
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
if (a.includes("
|
|
13580
|
-
if (a.includes("
|
|
14222
|
+
let adx = 0;
|
|
14223
|
+
let ady = 0;
|
|
14224
|
+
if (a.includes("left")) adx += hw;
|
|
14225
|
+
if (a.includes("right")) adx -= hw;
|
|
14226
|
+
if (a.includes("top")) ady -= hh;
|
|
14227
|
+
if (a.includes("bottom")) ady += hh;
|
|
14228
|
+
layer.origin[0] += adx;
|
|
14229
|
+
layer.origin[1] += ady;
|
|
14230
|
+
if (layer.localOrigin) {
|
|
14231
|
+
layer.localOrigin[0] += adx;
|
|
14232
|
+
layer.localOrigin[1] += ady;
|
|
14233
|
+
}
|
|
13581
14234
|
}
|
|
13582
14235
|
const em0 = TEXT_EM_SCALE * Math.max(1, layer.textPointsize);
|
|
13583
14236
|
const marginCap = wtext.textLayerHasTintMask(layer) ? 8 : 256;
|
|
@@ -13820,6 +14473,15 @@ function mountScene(rt, cfg) {
|
|
|
13820
14473
|
if (sb && sb.hasMediaHook) registerMediaHook(sb);
|
|
13821
14474
|
}
|
|
13822
14475
|
});
|
|
14476
|
+
const LOCAL_SLOT = {
|
|
14477
|
+
origin: "localOrigin",
|
|
14478
|
+
scale: "localScale",
|
|
14479
|
+
angles: "localAngles"
|
|
14480
|
+
};
|
|
14481
|
+
const fieldSlot = (layer, field) => {
|
|
14482
|
+
const slot = LOCAL_SLOT[field];
|
|
14483
|
+
return slot && layer && Array.isArray(layer[slot]) ? slot : field;
|
|
14484
|
+
};
|
|
13823
14485
|
for (const layer of scene.layers) {
|
|
13824
14486
|
const defs = layer.objectAnimations;
|
|
13825
14487
|
if (!defs) continue;
|
|
@@ -13830,11 +14492,13 @@ function mountScene(rt, cfg) {
|
|
|
13830
14492
|
const ctrl = anim.createAnimation(def.animation);
|
|
13831
14493
|
ctrl.field = field;
|
|
13832
14494
|
ctrl.baseValue = def.value;
|
|
13833
|
-
const
|
|
14495
|
+
const slot = fieldSlot(layer, field);
|
|
14496
|
+
const live2 = layer[slot];
|
|
13834
14497
|
ctrl.baseNumeric = Array.isArray(live2) ? live2.slice() : live2;
|
|
14498
|
+
ctrl.slot = slot;
|
|
13835
14499
|
layer.animationList.push(ctrl);
|
|
13836
14500
|
if (ctrl.name) layer.animations[ctrl.name] = ctrl;
|
|
13837
|
-
animRuns.push({ layer, field, ctrl });
|
|
14501
|
+
animRuns.push({ layer, field, slot, ctrl });
|
|
13838
14502
|
} catch (e) {
|
|
13839
14503
|
reportDiag(rt, cfg, `animation '${layer.name}.${field}' 建控制器失败: ${String(e.message).slice(0, 80)}`);
|
|
13840
14504
|
}
|
|
@@ -13899,7 +14563,8 @@ function mountScene(rt, cfg) {
|
|
|
13899
14563
|
});
|
|
13900
14564
|
if (sandbox) {
|
|
13901
14565
|
propSandboxes.push(sandbox);
|
|
13902
|
-
const
|
|
14566
|
+
const initSlot = fieldSlot(layer, field);
|
|
14567
|
+
const fieldVal = layer[initSlot];
|
|
13903
14568
|
const initArg = field === "angles" && Array.isArray(fieldVal) ? wtext.radToScriptAngles(fieldVal) : Array.isArray(fieldVal) ? { x: fieldVal[0] ?? 0, y: fieldVal[1] ?? 0, z: fieldVal[2] ?? 0 } : fieldVal;
|
|
13904
14569
|
sandbox.init(initArg);
|
|
13905
14570
|
sandbox.applyUserProperties(objUserProps);
|
|
@@ -13909,6 +14574,8 @@ function mountScene(rt, cfg) {
|
|
|
13909
14574
|
objectScriptRuns.push({
|
|
13910
14575
|
layer,
|
|
13911
14576
|
field,
|
|
14577
|
+
// 变换字段逐帧也在 local 槽上收发(与 init 同一空间)。
|
|
14578
|
+
slot: initSlot,
|
|
13912
14579
|
kind: field === "visible" ? "bool" : field === "alpha" || field === "brightness" ? "scalar" : "vec3",
|
|
13913
14580
|
sandbox
|
|
13914
14581
|
});
|
|
@@ -13972,6 +14639,7 @@ function mountScene(rt, cfg) {
|
|
|
13972
14639
|
window.__objScripts = objectScriptRuns;
|
|
13973
14640
|
}
|
|
13974
14641
|
window.__mediaHooks = mediaHooks;
|
|
14642
|
+
window.__sceneLayers = scene.layers;
|
|
13975
14643
|
window.__compositeStats = () => renderer.compositeStats?.() ?? null;
|
|
13976
14644
|
window.__compositeEnable = (on) => renderer.setCompositeEnabled?.(on);
|
|
13977
14645
|
window.__scene = scene;
|
|
@@ -14032,6 +14700,7 @@ function mountScene(rt, cfg) {
|
|
|
14032
14700
|
const playingVideos = [];
|
|
14033
14701
|
const playingAudios = [];
|
|
14034
14702
|
let lastRender = -Infinity;
|
|
14703
|
+
let lastAnimT = 0;
|
|
14035
14704
|
const renderLoop = (now) => {
|
|
14036
14705
|
if (disposed || rt.paused) return;
|
|
14037
14706
|
const fps = rt.cfg.sceneFps || 60;
|
|
@@ -14064,34 +14733,37 @@ function mountScene(rt, cfg) {
|
|
|
14064
14733
|
}
|
|
14065
14734
|
if (live?.windowTitle) live.windowTitle.pump();
|
|
14066
14735
|
else simWindow.update(t);
|
|
14736
|
+
const animDt = Math.max(0, t - lastAnimT);
|
|
14737
|
+
lastAnimT = t;
|
|
14067
14738
|
for (const run of animRuns) {
|
|
14068
|
-
run.ctrl.advance(
|
|
14739
|
+
run.ctrl.advance(animDt);
|
|
14069
14740
|
const field = run.field;
|
|
14741
|
+
const slot = run.slot || field;
|
|
14070
14742
|
const out = run.ctrl.applyTo(run.ctrl.baseNumeric);
|
|
14071
14743
|
if (Array.isArray(out)) {
|
|
14072
|
-
const cur = run.layer[
|
|
14744
|
+
const cur = run.layer[slot];
|
|
14073
14745
|
if (Array.isArray(cur)) for (let i = 0; i < out.length && i < cur.length; i++) cur[i] = out[i];
|
|
14074
14746
|
} else if (Number.isFinite(out)) {
|
|
14075
14747
|
if (field === "visible") run.layer[field] = !!out;
|
|
14076
|
-
else run.layer[
|
|
14748
|
+
else run.layer[slot] = out;
|
|
14077
14749
|
}
|
|
14078
14750
|
}
|
|
14079
14751
|
for (const run of generalAnimRuns) {
|
|
14080
|
-
run.ctrl.advance(
|
|
14752
|
+
run.ctrl.advance(animDt);
|
|
14081
14753
|
const out = run.ctrl.applyTo(run.ctrl.baseNumeric);
|
|
14082
14754
|
if (typeof out === "number" && Number.isFinite(out)) run.write(out);
|
|
14083
14755
|
else if (Array.isArray(out) && Number.isFinite(out[0])) run.write(out[0]);
|
|
14084
14756
|
}
|
|
14085
14757
|
for (const run of effectVisibleRuns) {
|
|
14086
14758
|
if (run.sandbox.disabled) continue;
|
|
14087
|
-
run.sandbox.engine.frametime =
|
|
14759
|
+
run.sandbox.engine.frametime = animDt;
|
|
14088
14760
|
run.sandbox.engine.runtime = t;
|
|
14089
14761
|
const ret = run.sandbox.callUpdate(!!run.effect.visible);
|
|
14090
14762
|
if (typeof ret === "boolean") run.effect.visible = ret;
|
|
14091
14763
|
}
|
|
14092
14764
|
for (const run of generalScriptRuns) {
|
|
14093
14765
|
if (run.sandbox.disabled) continue;
|
|
14094
|
-
run.sandbox.engine.frametime =
|
|
14766
|
+
run.sandbox.engine.frametime = animDt;
|
|
14095
14767
|
run.sandbox.engine.runtime = t;
|
|
14096
14768
|
const g = scene.general || {};
|
|
14097
14769
|
const cur = g[run.field] && typeof g[run.field] === "object" && "value" in g[run.field] ? g[run.field].value : g[run.field];
|
|
@@ -14099,10 +14771,16 @@ function mountScene(rt, cfg) {
|
|
|
14099
14771
|
if (ret !== void 0) run.write(ret);
|
|
14100
14772
|
}
|
|
14101
14773
|
const screenRes = { x: c.clientWidth || window.innerWidth || 1, y: c.clientHeight || window.innerHeight || 1 };
|
|
14774
|
+
for (const sb of propSandboxes) {
|
|
14775
|
+
if (!sb || sb.disabled) continue;
|
|
14776
|
+
sb.engine.frametime = animDt;
|
|
14777
|
+
sb.engine.runtime = t;
|
|
14778
|
+
sb.engine.screenResolution = screenRes;
|
|
14779
|
+
}
|
|
14102
14780
|
let visibilityDirty = false;
|
|
14103
14781
|
for (const run of objectScriptRuns) {
|
|
14104
14782
|
if (run.sandbox.disabled) continue;
|
|
14105
|
-
run.sandbox.engine.frametime =
|
|
14783
|
+
run.sandbox.engine.frametime = animDt;
|
|
14106
14784
|
run.sandbox.engine.runtime = t;
|
|
14107
14785
|
run.sandbox.engine.screenResolution = screenRes;
|
|
14108
14786
|
const cur = run.layer[run.field];
|
|
@@ -14123,20 +14801,23 @@ function mountScene(rt, cfg) {
|
|
|
14123
14801
|
const n = Number(ret);
|
|
14124
14802
|
if (Number.isFinite(n)) run.layer[run.field] = n;
|
|
14125
14803
|
} else {
|
|
14126
|
-
const
|
|
14804
|
+
const slot = run.slot || run.field;
|
|
14805
|
+
const lcur = run.layer[slot];
|
|
14806
|
+
const v = run.field === "angles" ? wtext.radToScriptAngles(lcur) : { x: lcur[0] || 0, y: lcur[1] || 0, z: lcur[2] || 0 };
|
|
14127
14807
|
const ret = run.sandbox.callUpdate(v);
|
|
14128
14808
|
const o = ret && typeof ret === "object" && "x" in ret ? ret : v;
|
|
14129
|
-
run.layer[
|
|
14809
|
+
run.layer[slot] = run.field === "angles" ? wtext.scriptAnglesToRad(o) : [o.x || 0, o.y || 0, o.z || 0];
|
|
14130
14810
|
}
|
|
14131
14811
|
}
|
|
14132
14812
|
if (visibilityDirty) recomputeVisibility();
|
|
14813
|
+
if (transformDirty.size) scn.recomposeWorld(scene.layers, transformDirty);
|
|
14133
14814
|
if (audioSim.enabled) {
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
-
|
|
14137
|
-
|
|
14138
|
-
|
|
14139
|
-
);
|
|
14815
|
+
hostAudio.pump();
|
|
14816
|
+
if (!hostAudio.active) {
|
|
14817
|
+
if (audioDriverRef.current) audioDriverRef.current.pump();
|
|
14818
|
+
else simAudio.update(t);
|
|
14819
|
+
}
|
|
14820
|
+
fillAudioBuffers(audioViews, activeAudioSnapshot());
|
|
14140
14821
|
}
|
|
14141
14822
|
if (attachFollows.length) {
|
|
14142
14823
|
mdl.followAttachments(attachFollows, t, getBoneOverrides);
|
|
@@ -14323,11 +15004,672 @@ function mountScene(rt, cfg) {
|
|
|
14323
15004
|
}
|
|
14324
15005
|
})();
|
|
14325
15006
|
}
|
|
15007
|
+
const SHIM_MARK = 'data-we-shim="1"';
|
|
15008
|
+
const SHIM_ATTR = "data-we-shim-src";
|
|
15009
|
+
function entryDirUrl(entryUrl) {
|
|
15010
|
+
try {
|
|
15011
|
+
const u = new URL(entryUrl);
|
|
15012
|
+
const path = u.pathname;
|
|
15013
|
+
const i = path.lastIndexOf("/");
|
|
15014
|
+
u.pathname = i < 0 ? "/" : path.slice(0, i + 1);
|
|
15015
|
+
u.hash = "";
|
|
15016
|
+
u.search = "";
|
|
15017
|
+
return u.href;
|
|
15018
|
+
} catch {
|
|
15019
|
+
const s = entryUrl.replace(/[#?].*$/, "");
|
|
15020
|
+
const i = s.lastIndexOf("/");
|
|
15021
|
+
return i < 0 ? s : s.slice(0, i + 1);
|
|
15022
|
+
}
|
|
15023
|
+
}
|
|
15024
|
+
function hasBlockingCsp(html) {
|
|
15025
|
+
const re = /<meta[^>]+http-equiv\s*=\s*["']?Content-Security-Policy["']?[^>]*>/gi;
|
|
15026
|
+
let m;
|
|
15027
|
+
while (m = re.exec(html)) {
|
|
15028
|
+
const tag = m[0];
|
|
15029
|
+
const content = /content\s*=\s*"([^"]*)"/i.exec(tag)?.[1] ?? /content\s*=\s*'([^']*)'/i.exec(tag)?.[1] ?? "";
|
|
15030
|
+
if (!/script-src/i.test(content)) continue;
|
|
15031
|
+
if (/script-src[^;]*'unsafe-inline'/i.test(content)) continue;
|
|
15032
|
+
if (/script-src[^;]*\*/i.test(content)) continue;
|
|
15033
|
+
return true;
|
|
15034
|
+
}
|
|
15035
|
+
return false;
|
|
15036
|
+
}
|
|
15037
|
+
function escapeScriptClose(js) {
|
|
15038
|
+
return js.replace(/<\/script/gi, "<\\/script");
|
|
15039
|
+
}
|
|
15040
|
+
function rewriteHtml(html, shimSource2, opts) {
|
|
15041
|
+
if (!html) html = "";
|
|
15042
|
+
if (html.includes(SHIM_MARK) || html.includes(SHIM_ATTR)) return html;
|
|
15043
|
+
const base = opts.baseHref && !/<base\b/i.test(html) ? `<base href="${opts.baseHref.replace(/"/g, """)}">` : "";
|
|
15044
|
+
const script = `<script ${SHIM_ATTR}="1">
|
|
15045
|
+
${escapeScriptClose(shimSource2)}
|
|
15046
|
+
<\/script>`;
|
|
15047
|
+
const seed = opts.seedScript && opts.seedScript.trim() ? `<script>
|
|
15048
|
+
${escapeScriptClose(opts.seedScript)}
|
|
15049
|
+
<\/script>` : "";
|
|
15050
|
+
const inject = `${base}${script}${seed}`;
|
|
15051
|
+
const headOpen = /<head(\s[^>]*)?>/i.exec(html);
|
|
15052
|
+
if (headOpen) {
|
|
15053
|
+
const at = headOpen.index + headOpen[0].length;
|
|
15054
|
+
return html.slice(0, at) + inject + html.slice(at);
|
|
15055
|
+
}
|
|
15056
|
+
const htmlOpen = /<html(\s[^>]*)?>/i.exec(html);
|
|
15057
|
+
if (htmlOpen) {
|
|
15058
|
+
const at = htmlOpen.index + htmlOpen[0].length;
|
|
15059
|
+
return html.slice(0, at) + `<head>${inject}</head>` + html.slice(at);
|
|
15060
|
+
}
|
|
15061
|
+
return `<!DOCTYPE html><html><head>${inject}</head><body>${html}</body></html>`;
|
|
15062
|
+
}
|
|
15063
|
+
const shimSource = '/**\n * WE 网页壁纸兼容 shim(注入到 iframe,必须在作者脚本之前执行)。\n *\n * 语料:本机库 42 张 web 壁纸扫描(2026-09)——\n * wallpaperPropertyListener 29 / RegisterAudioListener 22 /\n * RequestRandomFileForProperty 8 / userDirectoryFiles* 9 /\n * Media*Listener 2 / PluginListener 2\n *\n * 官方 CEF 在任何壁纸脚本前就把这些做成原生函数;工坊顶层直接注册。\n * 本文件作为 <head> 首个 classic script 插入。\n *\n * 父页控制面 __we*(main.ts weShimCall / web.ts 泵):\n * __weSetPaused / __weSetFps / __weSetVolume / __weApplyProps / __weSeedProps\n * __wePushAudio(arr128)\n * __wePushMedia(event) — {op, payload} 见下\n * __wePushDirectoryFiles(prop, files) / __weRemoveDirectoryFiles(prop, files)\n * __weRewriteFileUrl(s) — file:/// → 同源相对(HTTP 页);空 file:/// → ""\n * __wePushPointer(x, y, buttons) / __wePointerLeave() — 外部指针注入(见文末)\n */\n(function (w) {\n "use strict";\n try {\n if (w.document && w.document.documentElement) {\n w.document.documentElement.setAttribute("data-we-shim", "1");\n }\n } catch (_) {\n /* 忽略 */\n }\n\n var audioListener = null;\n var propertyListener = null;\n var paused = false;\n var fps = 60;\n var volume = 0;\n var pendingProps = null;\n var pendingGeneral = null;\n var rafMap = Object.create(null);\n var rafCounter = 0;\n var origRaf = w.requestAnimationFrame.bind(w);\n var origCaf = w.cancelAnimationFrame.bind(w);\n\n // 官方 CEF 以文件系统为源,作者普遍 `\'file:///\' + value`。HTTP 同源页里\n // file:///files/x.webm 加载失败;空 value 变成 file:///(1748506393)。\n // file: 协议页保持原样(真本地嵌入)。\n function rewriteBareFileUrl(url) {\n if (typeof url !== "string") return url;\n var s = url.trim();\n if (!/^file:/i.test(s)) return s;\n try {\n var loc = w.location;\n if (loc && loc.protocol === "file:") return s;\n } catch (_) {\n /* 忽略 */\n }\n var rest = s.replace(/^file:\\/\\//i, "").replace(/^\\/+/, "");\n if (!rest) return "";\n if (/^[a-zA-Z][:|]/.test(rest)) return "";\n if (/^(Users|home|tmp|var|etc|private|Volumes)\\//.test(rest)) return "";\n try {\n var href = w.location && w.location.href;\n if (href) return new URL(rest, href).href;\n } catch (_) {\n /* 忽略 */\n }\n return rest;\n }\n\n function rewriteWeFileUrl(input) {\n if (typeof input !== "string") return input;\n if (/url\\(/i.test(input)) {\n return input.replace(/url\\(\\s*([\'"]?)([^)\'"]*?)\\1\\s*\\)/gi, function (_m, q, inner) {\n var next = rewriteBareFileUrl(inner);\n if (!next) return "none";\n var quote = q || \'"\';\n return "url(" + quote + next + quote + ")";\n });\n }\n return rewriteBareFileUrl(input);\n }\n\n w.__weRewriteFileUrl = rewriteWeFileUrl;\n\n function installFileUrlHooks() {\n try {\n if (w.Element && w.Element.prototype && typeof w.Element.prototype.setAttribute === "function") {\n var origSetAttr = w.Element.prototype.setAttribute;\n w.Element.prototype.setAttribute = function (name, value) {\n var n = String(name || "").toLowerCase();\n if (n === "src" || n === "href" || n === "poster") value = rewriteWeFileUrl(value);\n return origSetAttr.call(this, name, value);\n };\n }\n } catch (_) {\n /* 无 DOM 的 verifier 跳过 */\n }\n var ctorNames = ["HTMLImageElement", "HTMLMediaElement", "HTMLSourceElement", "HTMLScriptElement"];\n for (var i = 0; i < ctorNames.length; i++) {\n try {\n var Ctor = w[ctorNames[i]];\n if (!Ctor || !Ctor.prototype) continue;\n var desc = Object.getOwnPropertyDescriptor(Ctor.prototype, "src");\n if (!desc || typeof desc.set !== "function") continue;\n (function (d) {\n Object.defineProperty(Ctor.prototype, "src", {\n configurable: true,\n enumerable: d.enumerable,\n get: d.get,\n set: function (v) {\n d.set.call(this, rewriteWeFileUrl(v));\n },\n });\n })(desc);\n } catch (_) {\n /* 忽略单个原型 */\n }\n }\n try {\n var styleDesc =\n w.HTMLElement && Object.getOwnPropertyDescriptor(w.HTMLElement.prototype, "style");\n // Chromium 的 backgroundImage 不是原型自有描述符,只能包 HTMLElement.style 的 Proxy。\n if (styleDesc && typeof styleDesc.get === "function" && w.Proxy && w.WeakMap) {\n var styleCache = new w.WeakMap();\n Object.defineProperty(w.HTMLElement.prototype, "style", {\n configurable: true,\n enumerable: styleDesc.enumerable,\n get: function () {\n var raw = styleDesc.get.call(this);\n if (!raw) return raw;\n var cached = styleCache.get(raw);\n if (cached) return cached;\n var proxy = new w.Proxy(raw, {\n set: function (target, prop, value) {\n if (typeof value === "string" && typeof prop === "string" && /background/i.test(prop)) {\n value = rewriteWeFileUrl(value);\n }\n target[prop] = value;\n return true;\n },\n get: function (target, prop) {\n var v = target[prop];\n if (typeof v === "function") return v.bind(target);\n return v;\n },\n });\n styleCache.set(raw, proxy);\n return proxy;\n },\n set: styleDesc.set,\n });\n }\n var styleProto = w.CSSStyleDeclaration && w.CSSStyleDeclaration.prototype;\n if (styleProto && typeof styleProto.setProperty === "function") {\n var origSetProp = styleProto.setProperty;\n styleProto.setProperty = function (name, value, priority) {\n if (typeof value === "string" && /background/i.test(String(name || ""))) {\n value = rewriteWeFileUrl(value);\n }\n return origSetProp.call(this, name, value, priority);\n };\n }\n } catch (_) {\n /* 忽略 */\n }\n }\n installFileUrlHooks();\n\n // propertyName → string[](绝对/相对路径;随机文件从此抽)\n var directoryFiles = Object.create(null);\n\n var mediaListeners = {\n properties: null,\n thumbnail: null,\n playback: null,\n timeline: null,\n status: null,\n };\n // 晚注册时回放最近一帧(作者脚本常在 DOMContentLoaded 后才 Register)\n var lastMedia = {\n properties: null,\n thumbnail: null,\n playback: null,\n timeline: null,\n status: null,\n };\n\n function callApplyUserProperties(props) {\n if (!propertyListener || typeof propertyListener.applyUserProperties !== "function") return;\n try {\n propertyListener.applyUserProperties(props || {});\n } catch (_) {\n /* 壁纸脚本抛错不打断宿主 */\n }\n }\n\n function callApplyGeneralProperties(props) {\n if (!propertyListener || typeof propertyListener.applyGeneralProperties !== "function") return;\n try {\n propertyListener.applyGeneralProperties(props || {});\n } catch (_) {\n /* 忽略 */\n }\n }\n\n function callSetPaused(v) {\n if (!propertyListener || typeof propertyListener.setPaused !== "function") return;\n try {\n propertyListener.setPaused(!!v);\n } catch (_) {\n /* 忽略 */\n }\n }\n\n function callDirectoryAdded(prop, files) {\n if (!propertyListener || typeof propertyListener.userDirectoryFilesAddedOrChanged !== "function")\n return;\n try {\n propertyListener.userDirectoryFilesAddedOrChanged(prop, files);\n } catch (_) {\n /* 忽略 */\n }\n }\n\n function callDirectoryRemoved(prop, files) {\n if (!propertyListener || typeof propertyListener.userDirectoryFilesRemoved !== "function") return;\n try {\n propertyListener.userDirectoryFilesRemoved(prop, files);\n } catch (_) {\n /* 忽略 */\n }\n }\n\n function flushPending() {\n if (pendingProps) {\n var p = pendingProps;\n pendingProps = null;\n callApplyUserProperties(p);\n }\n if (pendingGeneral) {\n var g = pendingGeneral;\n pendingGeneral = null;\n callApplyGeneralProperties(g);\n }\n }\n\n /**\n * 工坊常在 React render 里写 `window.wallpaperPropertyListener = {…}`(2905017768)。\n * 官方 CEF 不会在赋值当下同步回调 setPaused/apply*;若我们同步 flush,\n * 等于 render 中 setState → React 熔断 → #root 空(一片黑)。\n */\n function afterAssign(fn) {\n try {\n if (typeof w.queueMicrotask === "function") w.queueMicrotask(fn);\n else w.setTimeout(fn, 0);\n } catch (_) {\n try {\n fn();\n } catch (_) {\n /* 忽略 */\n }\n }\n }\n\n function safeCall(fn, arg) {\n if (typeof fn !== "function") return;\n try {\n fn(arg);\n } catch (_) {\n /* 忽略 */\n }\n }\n\n // —— 媒体集成枚举(3747222633:缺省时 PLAYBACK_PLAYING||0 会把「播放」当成 0)——\n w.wallpaperMediaIntegration = {\n PLAYBACK_STOPPED: 0,\n PLAYBACK_PLAYING: 1,\n PLAYBACK_PAUSED: 2,\n };\n\n // —— 官方 API:音频 ——\n w.wallpaperRegisterAudioListener = function (cb) {\n audioListener = typeof cb === "function" ? cb : null;\n };\n\n // —— 官方 API:媒体 ——\n w.wallpaperRegisterMediaPropertiesListener = function (cb) {\n mediaListeners.properties = typeof cb === "function" ? cb : null;\n if (mediaListeners.properties && lastMedia.properties) {\n safeCall(mediaListeners.properties, lastMedia.properties);\n }\n };\n w.wallpaperRegisterMediaThumbnailListener = function (cb) {\n mediaListeners.thumbnail = typeof cb === "function" ? cb : null;\n if (mediaListeners.thumbnail && lastMedia.thumbnail) {\n safeCall(mediaListeners.thumbnail, lastMedia.thumbnail);\n }\n };\n w.wallpaperRegisterMediaPlaybackListener = function (cb) {\n mediaListeners.playback = typeof cb === "function" ? cb : null;\n if (mediaListeners.playback && lastMedia.playback) {\n safeCall(mediaListeners.playback, lastMedia.playback);\n }\n };\n w.wallpaperRegisterMediaTimelineListener = function (cb) {\n mediaListeners.timeline = typeof cb === "function" ? cb : null;\n if (mediaListeners.timeline && lastMedia.timeline) {\n safeCall(mediaListeners.timeline, lastMedia.timeline);\n }\n };\n w.wallpaperRegisterMediaStatusListener = function (cb) {\n mediaListeners.status = typeof cb === "function" ? cb : null;\n if (mediaListeners.status && lastMedia.status) {\n safeCall(mediaListeners.status, lastMedia.status);\n }\n };\n\n // —— 官方 API:随机文件(slideshow)——\n // 回调签名:function(propertyName, filePath)。无库存文件时 filePath 为空串(语料 if(i) 守卫)。\n w.wallpaperRequestRandomFileForProperty = function (propertyName, callback) {\n if (typeof callback !== "function") return;\n var prop = String(propertyName || "");\n var list = directoryFiles[prop];\n var path = "";\n if (list && list.length) {\n path = String(list[(Math.random() * list.length) | 0] || "");\n }\n try {\n callback(prop, path);\n } catch (_) {\n /* 忽略 */\n }\n };\n\n // —— PropertyListener(getter/setter;回调延后到微任务,见 afterAssign)——\n // 官方在页面加载完成后才发全量属性/暂停状态;首屏脚本(body onLoad=init 等)常\n // 假设属性到达时 DOM/场景已初始化(827982449:applyUserProperties→cl() 在 load 前\n // 跑会撞上未创建的 scene/material)。未加载完成时等 window load + 一个宏任务\n // (保证排在 onLoad 属性处理器之后),已加载完成则微任务即发。\n function whenPageReady(fn) {\n var ready = "complete";\n try {\n ready = w.document.readyState;\n } catch (_) {\n /* 忽略 */\n }\n if (ready === "complete") {\n afterAssign(fn);\n return;\n }\n try {\n w.addEventListener("load", function () {\n // setTimeout 保证排在 load 同步链(onLoad 处理器)之后\n w.setTimeout(fn, 0);\n }, { once: true });\n } catch (_) {\n afterAssign(fn);\n }\n }\n Object.defineProperty(w, "wallpaperPropertyListener", {\n configurable: true,\n enumerable: true,\n get: function () {\n return propertyListener;\n },\n set: function (v) {\n var next = v && typeof v === "object" ? v : null;\n var prev = propertyListener;\n propertyListener = next;\n if (!next) return;\n // 仅首次注册补发挂载状态。官方 CEF 从不在赋值当下回调;2905017768 等 React 壁纸在\n // 渲染体里重新赋值(新对象字面量),若每次都补 setPaused 会形成\n // 渲染 → 赋值 → 补发 setState → 再渲染 的微任务死循环(点下一曲整页卡死)。\n if (prev) return;\n whenPageReady(function () {\n flushPending();\n callApplyGeneralProperties({ fps: fps });\n callSetPaused(paused);\n // 已缓存的目录文件补推一次(作者可能后挂 userDirectoryFilesAddedOrChanged)\n for (var prop in directoryFiles) {\n if (Object.prototype.hasOwnProperty.call(directoryFiles, prop) && directoryFiles[prop].length) {\n callDirectoryAdded(prop, directoryFiles[prop].slice());\n }\n }\n });\n },\n });\n\n // —— Plugin(iCUE 等;无硬件时空实现,避免 if 判断失败)——\n if (!w.wallpaperPluginListener) {\n w.wallpaperPluginListener = {\n onPluginLoaded: function () {},\n };\n }\n\n // —— 定时器冻结:官方暂停 = "fully freeze the process that renders the wallpaper",\n // rAF 已在节流层挂起,这里冻结定时器:暂停期间新建的挂起登记、恢复时按原延迟/间隔\n // 重新启动;**已启动**的真定时器到期由包装回调拦下——timeout 转挂起(恢复后立即补跑,\n // 近似官方的剩余等待),interval 直接跳过该周期(恢复后从下个周期继续)。\n var pendTimers = [];\n var tmSeq = 0;\n var TM_BASE = 0x40000000; // 假 id 段,避免与真实 timer id 混淆\n var origST = w.setTimeout;\n var origSI = w.setInterval;\n var origCTO = w.clearTimeout;\n var origCIT = w.clearInterval;\n function guardTimeout(fn) {\n if (typeof fn !== "function") return fn;\n return function () {\n if (paused) {\n pendTimers.push({ id: 0, kind: "t", fn: fn, ms: 1, extra: [] });\n return;\n }\n return fn.apply(this, arguments);\n };\n }\n function guardInterval(fn) {\n if (typeof fn !== "function") return fn;\n return function () {\n if (paused) return;\n return fn.apply(this, arguments);\n };\n }\n function startTimer(kind, fn, ms, extra) {\n if (paused) {\n var id = TM_BASE + ++tmSeq;\n pendTimers.push({ id: id, kind: kind, fn: fn, ms: ms, extra: extra });\n return id;\n }\n var args = [kind === "t" ? guardTimeout(fn) : guardInterval(fn), ms].concat(extra);\n return (kind === "t" ? origST : origSI).apply(w, args);\n }\n w.setTimeout = function (fn, ms) {\n return startTimer("t", fn, ms, Array.prototype.slice.call(arguments, 2));\n };\n w.setInterval = function (fn, ms) {\n return startTimer("i", fn, ms, Array.prototype.slice.call(arguments, 2));\n };\n function unpend(id) {\n for (var i = 0; i < pendTimers.length; i++) {\n if (pendTimers[i].id === id) {\n pendTimers.splice(i, 1);\n return true;\n }\n }\n return false;\n }\n w.clearTimeout = function (id) {\n if (unpend(id)) return;\n origCTO.call(w, id);\n };\n w.clearInterval = function (id) {\n if (unpend(id)) return;\n origCIT.call(w, id);\n };\n function resumeTimers() {\n var list = pendTimers;\n pendTimers = [];\n for (var i = 0; i < list.length; i++) {\n var t = list[i];\n (t.kind === "t" ? origST : origSI).call(w, t.fn, t.ms, t.extra);\n }\n }\n\n /**\n * 恢复暂停期间被挂起的 rAF 请求。\n *\n * **不补跑这些回调,主循环就永久断掉**(1278092907 Monstercat:`draw()` 在函数体\n * 开头就 `requestAnimationFrame(draw)` 再画,暂停期间那次请求被登记成 hold,\n * 恢复后没人跑它 → 整条链没有下一帧,画面永久定格,且没有任何报错)。\n * 这是 rAF 自递归的通用形态,不是这一张的特例。\n *\n * 走 `w.requestAnimationFrame` 而不是 `origRaf`:此时已 unpaused,要让它重新经过\n * 节流层(低 fps 时该走 setTimeout 路径),并照常发 we-frame 打点。\n */\n function resumeRafHolds() {\n var holds = [];\n for (var id in rafMap) {\n if (!Object.prototype.hasOwnProperty.call(rafMap, id)) continue;\n if (rafMap[id] && rafMap[id].kind === "hold") {\n holds.push(rafMap[id].cb);\n delete rafMap[id];\n }\n }\n for (var i = 0; i < holds.length; i++) {\n try {\n w.requestAnimationFrame(holds[i]);\n } catch (_) {\n /* 单个回调重挂失败不影响其它 */\n }\n }\n }\n\n // —— 媒体音量:对齐官方 CEF 语义(浏览器级主音量与作者页面内音量独立相乘)——\n // 作者常在播放前重设 a.volume = uiVolume(Bocchi),且音频多为 `new Audio()` 不进\n // DOM——querySelectorAll 找不到、直接覆盖 volume 又会被作者回写。因此 hook 原型:\n // setter 记作者值,元素实际音量 = 作者值 × 主音量;`__weSetVolume` 改系数并刷新\n // 全部活实例(DOM 内 + Audio 构造器登记的 WeakRef)。\n var hostVolume = 1;\n var liveMedia = []; // WeakRef<HTMLMediaElement>\n function trackMedia(el) {\n if (!w.WeakRef) return;\n liveMedia.push(new w.WeakRef(el));\n }\n function applyMediaVolume(el) {\n if (el.__weBaseVol != null) {\n mediaVolDesc.set.call(el, el.__weBaseVol * hostVolume);\n } else {\n mediaVolDesc.set.call(el, hostVolume);\n }\n var baseMuted = !!el.__weBaseMuted;\n mediaMutedDesc.set.call(el, baseMuted || hostVolume <= 0);\n }\n function refreshAllMediaVolume() {\n try {\n var nodes = w.document.querySelectorAll("audio,video");\n for (var i = 0; i < nodes.length; i++) applyMediaVolume(nodes[i]);\n } catch (_) {\n /* 忽略 */\n }\n for (var j = liveMedia.length - 1; j >= 0; j--) {\n var el = liveMedia[j].deref();\n if (!el) {\n liveMedia.splice(j, 1);\n continue;\n }\n applyMediaVolume(el);\n }\n }\n var mediaVolDesc = null;\n var mediaMutedDesc = null;\n function installMediaVolumeHooks() {\n try {\n if (!w.HTMLMediaElement || !w.HTMLMediaElement.prototype) return;\n var proto = w.HTMLMediaElement.prototype;\n mediaVolDesc = Object.getOwnPropertyDescriptor(proto, "volume");\n mediaMutedDesc = Object.getOwnPropertyDescriptor(proto, "muted");\n if (mediaVolDesc && typeof mediaVolDesc.set === "function") {\n Object.defineProperty(proto, "volume", {\n configurable: true,\n enumerable: mediaVolDesc.enumerable,\n get: function () {\n return this.__weBaseVol != null ? this.__weBaseVol : mediaVolDesc.get.call(this);\n },\n set: function (v) {\n this.__weBaseVol = Math.max(0, Math.min(1, Number(v) || 0));\n mediaVolDesc.set.call(this, this.__weBaseVol * hostVolume);\n },\n });\n }\n if (mediaMutedDesc && typeof mediaMutedDesc.set === "function") {\n Object.defineProperty(proto, "muted", {\n configurable: true,\n enumerable: mediaMutedDesc.enumerable,\n get: function () {\n return this.__weBaseMuted != null\n ? this.__weBaseMuted || hostVolume <= 0\n : mediaMutedDesc.get.call(this);\n },\n set: function (v) {\n this.__weBaseMuted = !!v;\n mediaMutedDesc.set.call(this, !!v || hostVolume <= 0);\n },\n });\n }\n // `new Audio()` 不进 DOM:构造器登记 WeakRef 以便主音量变化时刷新\n if (typeof w.Audio === "function" && w.WeakRef) {\n var OrigAudio = w.Audio;\n function WrappedAudio(src) {\n var a = new OrigAudio(src);\n trackMedia(a);\n applyMediaVolume(a);\n return a;\n }\n WrappedAudio.prototype = OrigAudio.prototype;\n w.Audio = WrappedAudio;\n }\n } catch (_) {\n /* 无媒体环境的 verifier 跳过 */\n }\n }\n installMediaVolumeHooks();\n\n // —— 父页控制面 ——\n // 官方 setPaused 只在暂停状态实际变化时调用一次;重复调用去重。\n // 暂停还要冻结页内媒体:官方是进程级冻结(无声、解码器可回收),作者的\n // setPaused 常只管自己的逻辑。只记录「我们代为暂停」的元素,恢复时仅还原这部分,\n // 不碰作者自己暂停的。\n var weFrozenMedia = [];\n function freezePageMedia() {\n weFrozenMedia.length = 0;\n try {\n var nodes = w.document.querySelectorAll("audio,video");\n for (var i = 0; i < nodes.length; i++) {\n if (!nodes[i].paused) {\n weFrozenMedia.push(nodes[i]);\n try {\n nodes[i].pause();\n } catch (_) {\n /* 忽略 */\n }\n }\n }\n } catch (_) {\n /* 忽略 */\n }\n }\n function thawPageMedia() {\n for (var i = 0; i < weFrozenMedia.length; i++) {\n try {\n var p = weFrozenMedia[i].play();\n if (p && p.catch) p.catch(function () {});\n } catch (_) {\n /* 忽略 */\n }\n }\n weFrozenMedia.length = 0;\n }\n\n /**\n * 暂停还要冻结 **CSS 动画 / 过渡**(Web Animations 时间轴)。\n *\n * rAF 与定时器冻结管不到它们:CSS `animation` 由浏览器**合成器**独立驱动,\n * 与 JS 主线程无关。1444432396 Glitch Clock 的整个视觉(背景移动、抖动、故障\n * 闪烁)是 10 处 `animation: … infinite`,只有时钟文字走 `setInterval` ——\n * 暂停后画面照旧动个不停,用户看到的就是「无法暂停」(实测暂停期间 6 个动画\n * 全为 `playState:"running"`,`currentTime` 700ms 推进整 700ms)。\n *\n * 官方暂停语义是「fully freeze the process that renders the wallpaper」,\n * 合成器动画自然也在冻结范围内。\n *\n * 与媒体冻结同一条纪律:**只记录我们代为暂停的**,恢复时仅还原这部分——\n * 作者自己用 `animation-play-state: paused` 停下的(常见于 hover 才播的装饰)\n * 不能被我们唤醒。`getAnimations()` 拿的是活动动画对象,`pause()`/`play()`\n * 直接作用在时间轴上,比改 `style.animationPlayState` 干净(后者会污染作者的\n * 内联样式,且被作者下一次样式写入覆盖)。\n */\n var weFrozenAnims = [];\n function freezePageAnimations() {\n weFrozenAnims.length = 0;\n try {\n if (typeof w.document.getAnimations !== "function") return;\n var anims = w.document.getAnimations();\n for (var i = 0; i < anims.length; i++) {\n var a = anims[i];\n if (a && a.playState === "running") {\n weFrozenAnims.push(a);\n try {\n a.pause();\n } catch (_) {\n /* 个别动画不可暂停时跳过 */\n }\n }\n }\n } catch (_) {\n /* 旧引擎无 getAnimations:退化为不冻结,不报错 */\n }\n }\n function thawPageAnimations() {\n for (var i = 0; i < weFrozenAnims.length; i++) {\n try {\n weFrozenAnims[i].play();\n } catch (_) {\n /* 已被作者移除的动画忽略 */\n }\n }\n weFrozenAnims.length = 0;\n }\n w.__weSetPaused = function (v) {\n var next = !!v;\n if (next === paused) return;\n paused = next;\n if (paused) {\n callSetPaused(true);\n freezePageMedia();\n freezePageAnimations();\n } else {\n callSetPaused(false);\n thawPageMedia();\n thawPageAnimations();\n resumeTimers();\n // rAF 挂起项必须补跑,否则自递归的主循环永久断链(1278092907)\n resumeRafHolds();\n }\n };\n\n w.__weSetFps = function (n) {\n var next = Number(n);\n if (!Number.isFinite(next) || next <= 0) return;\n fps = next;\n callApplyGeneralProperties({ fps: fps });\n };\n\n w.__weSetVolume = function (v) {\n var next = Math.max(0, Math.min(1, Number(v) || 0));\n volume = next;\n hostVolume = next;\n refreshAllMediaVolume();\n };\n\n w.__weApplyProps = function (props) {\n if (!props || typeof props !== "object") return;\n // file 属性:值是路径时登记进随机池(单文件 slideshow)\n try {\n for (var key in props) {\n if (!Object.prototype.hasOwnProperty.call(props, key)) continue;\n var ent = props[key];\n var val = ent && typeof ent === "object" && "value" in ent ? ent.value : ent;\n if (typeof val === "string" && val !== "" && /\\.(png|jpe?g|gif|webp|webm|mp4|bmp)$/i.test(val)) {\n directoryFiles[key] = [val];\n }\n }\n } catch (_) {\n /* 忽略 */\n }\n if (!propertyListener || typeof propertyListener.applyUserProperties !== "function") {\n pendingProps = props;\n return;\n }\n callApplyUserProperties(props);\n };\n\n w.__weSeedProps = function (props) {\n if (!props || typeof props !== "object") return;\n if (propertyListener && typeof propertyListener.applyUserProperties === "function") {\n w.__weApplyProps(props);\n } else {\n pendingProps = props;\n }\n };\n\n w.__wePushAudio = function (arr) {\n if (paused || !audioListener) return;\n try {\n audioListener(arr);\n } catch (_) {\n /* 忽略 */\n }\n };\n\n /**\n * 媒体事件泵。payload 形态对齐官方:\n * { op:"properties", title, artist, album, albumArtist }\n * { op:"thumbnail", thumbnail, primaryColor, textColor, ... }\n * { op:"playback", state } // 0/1/2\n * { op:"timeline", position, duration }\n * { op:"status", enabled }\n */\n w.__wePushMedia = function (payload) {\n if (!payload || typeof payload !== "object") return;\n var op = payload.op;\n if (op === "properties") {\n lastMedia.properties = payload;\n safeCall(mediaListeners.properties, payload);\n } else if (op === "thumbnail") {\n lastMedia.thumbnail = payload;\n safeCall(mediaListeners.thumbnail, payload);\n } else if (op === "playback") {\n lastMedia.playback = payload;\n safeCall(mediaListeners.playback, payload);\n } else if (op === "timeline") {\n lastMedia.timeline = payload;\n safeCall(mediaListeners.timeline, payload);\n } else if (op === "status") {\n lastMedia.status = payload;\n safeCall(mediaListeners.status, payload);\n }\n };\n\n /** 目录文件列表(首次或追加)。files: string[] */\n w.__wePushDirectoryFiles = function (propertyName, files) {\n var prop = String(propertyName || "");\n if (!prop || !Array.isArray(files)) return;\n var cleaned = [];\n for (var i = 0; i < files.length; i++) {\n if (files[i] != null && String(files[i]) !== "") cleaned.push(String(files[i]));\n }\n if (!directoryFiles[prop]) directoryFiles[prop] = [];\n // 首次全量替换语义由调用方决定;这里 concat 去重\n var seen = Object.create(null);\n for (var j = 0; j < directoryFiles[prop].length; j++) seen[directoryFiles[prop][j]] = 1;\n var added = [];\n for (var k = 0; k < cleaned.length; k++) {\n if (!seen[cleaned[k]]) {\n seen[cleaned[k]] = 1;\n directoryFiles[prop].push(cleaned[k]);\n added.push(cleaned[k]);\n }\n }\n if (added.length) callDirectoryAdded(prop, added);\n };\n\n w.__weRemoveDirectoryFiles = function (propertyName, files) {\n var prop = String(propertyName || "");\n if (!prop || !Array.isArray(files) || !directoryFiles[prop]) return;\n var removeSet = Object.create(null);\n for (var i = 0; i < files.length; i++) removeSet[String(files[i])] = 1;\n var kept = [];\n var removed = [];\n for (var j = 0; j < directoryFiles[prop].length; j++) {\n var f = directoryFiles[prop][j];\n if (removeSet[f]) removed.push(f);\n else kept.push(f);\n }\n directoryFiles[prop] = kept;\n if (removed.length) callDirectoryRemoved(prop, removed);\n };\n\n // —— 外部指针注入(桌面 underlay 层收不到鼠标事件,父页经 __wp.pushPointer 推入)——\n //\n // 场景壁纸那条通道是「写一个状态对象、渲染器每帧读」(render/pointer.js);网页壁纸\n // 没有这样的单一消费点 —— 作者代码就是**监听 DOM 事件**的,所以这里必须把推送\n // 还原成一串合成事件。语料(本机 49 张 web):mousemove 24 张、click 29 张、\n // mouseover/out 17 张、mouseenter/leave 8 张、pointer* 16 张(createjs 系一律走\n // pointerdown/move/up)、.button 18 张、.which 17 张、pointerId/relatedTarget 15 张。\n //\n // 三条要点(都有语料依据,改错了会静默失效):\n //\n // 1. **必须 elementFromPoint 按命中元素派发**,不能一律打 document。作者既有挂\n // document/window 的(15 张,靠冒泡收到),也有挂 canvas 上读 `event.offsetX`\n // 的(1748506393 流体 `pointers[0].dx = (e.offsetX - …)`)。offsetX/offsetY 由\n // 浏览器按 target 的 padding box 现算 —— target 打错就是错的偏移,且无任何报错。\n // pageX/pageY 同理由 clientX + 滚动量现算,不用我们填。\n //\n // 2. **over/out/enter/leave 链要按 W3C 语义补全**。1748506393 靠 canvas 的\n // `mouseenter` 把 `pointers[0].down` 置 true(不进这个分支则鼠标怎么动都不出染料)、\n // 靠 window 的 `mouseleave` 复位;1081733658 animatedGrid 靠 `document.body` 的\n // mouseover/mouseleave 起停整个网格动画。leave/enter 不冒泡,必须自己沿祖先链走到\n // 最近公共祖先,只发生变化的那一段。\n //\n // 3. **click 要靠 down/up 边缘合成**,且 down 与 up 的 target 不同(拖拽)时不发。\n // 29 张听 click 是最大的消费方;轮询推送里没有「点击」这个事件,只有按键掩码的\n // 跳变,边缘丢了就等于整类交互消失。\n //\n // 硬限制(写在这里避免反复试):CSS `:hover` 由浏览器自己的 hit-test 驱动,合成事件\n // 永远点不亮它(18 张含 `:hover`)—— 纯 CSS hover 动画的壁纸无法用注入通道响应,\n // 这不是实现缺陷,是合成事件的固有边界。\n var ptrHas = false; // 是否收到过推送(首帧 movement 归零用)\n var ptrX = 0;\n var ptrY = 0;\n var ptrButtons = 0;\n var ptrTarget = null; // 上次命中元素(over/out 链的旧端)\n var ptrDownTarget = null; // 按下时的命中元素(click 判定)\n var ptrLastClickTime = 0;\n var ptrLastClickTarget = null;\n /** 双击判定窗口(ms)。与主流浏览器一致,语料里 5 张听 dblclick。 */\n var PTR_DBLCLICK_MS = 500;\n\n function ptrRoot() {\n try {\n return w.document.body || w.document.documentElement || null;\n } catch (_) {\n return null;\n }\n }\n\n function ptrHitTest(x, y) {\n try {\n if (typeof w.document.elementFromPoint === "function") {\n var el = w.document.elementFromPoint(x, y);\n if (el) return el;\n }\n } catch (_) {\n /* 忽略 */\n }\n return ptrRoot();\n }\n\n /** node → [node, parent, …, root];用 parentNode 而非 parentElement,\n * 这样 document / documentElement 也在链里(作者挂 document 的 leave 要收到)。 */\n function ptrChain(node) {\n var out = [];\n var n = node;\n while (n) {\n out.push(n);\n try {\n n = n.parentNode || null;\n } catch (_) {\n n = null;\n }\n }\n return out;\n }\n\n function ptrCommonAncestor(a, b) {\n if (!a || !b) return null;\n var ca = ptrChain(a);\n var seen = [];\n for (var i = 0; i < ca.length; i++) seen.push(ca[i]);\n var cb = ptrChain(b);\n for (var j = 0; j < cb.length; j++) {\n for (var k = 0; k < seen.length; k++) {\n if (seen[k] === cb[j]) return cb[j];\n }\n }\n return null;\n }\n\n /**\n * 造一个合成鼠标/指针事件。\n *\n * `PointerEvent` 优先:createjs 一族(语料 7 张)只挂 pointerdown/move/up,\n * 且会读 `pointerId` / `pointerType` / `isPrimary`。环境没有 PointerEvent 时\n * 退回 MouseEvent(事件名照旧,作者的 addEventListener(\'pointermove\') 仍能收到)。\n */\n function ptrMakeEvent(type, x, y, opts) {\n var o = opts || {};\n var isPointer = type.indexOf("pointer") === 0;\n var init = {\n bubbles: o.bubbles !== false,\n cancelable: o.cancelable !== false,\n // composed:作者把 canvas 放进 shadow DOM 时事件要能穿出来\n composed: true,\n view: w,\n detail: o.detail || 0,\n clientX: x,\n clientY: y,\n // screenX/screenY 是 init 字段(不像 pageX/offsetX 那样现算)。iframe 里\n // 只能按外层窗口原点近似;16 张读 screenX,多用于算相对位移而非绝对定位。\n screenX: x + (Number(w.screenX) || 0),\n screenY: y + (Number(w.screenY) || 0),\n // button:**移动/悬停类事件必须是 -1**,只有 down/up/click 才是 0(左)/1(中)/2(右)。\n // 这条是 W3C 规定的「没有按键状态变化」哨兵值,不是可省的细节:GameMaker HTML5\n // 导出的运行时(2517518192 FNAF)在 pointermove 分支里照抄 `_tq = e.button` 再\n // `_mq |= (1 << _tq)`,而 _mq 只在 pointerup/out 才清零 —— 填 0 等于告诉游戏\n // 「左键一直按着」,鼠标只是移过去就永久卡在按下态(且没有任何报错)。\n button: o.button != null ? o.button : -1,\n buttons: o.buttons != null ? o.buttons : ptrButtons,\n movementX: o.movementX || 0,\n movementY: o.movementY || 0,\n ctrlKey: false,\n shiftKey: false,\n altKey: false,\n metaKey: false,\n };\n if ("relatedTarget" in o) init.relatedTarget = o.relatedTarget || null;\n // `button: -1` 无法经 MouseEvent 构造器表达:Chromium 把 -1 规范化成 0\n // (实测 `new MouseEvent("x", {button:-1}).button === 0`,而 -2 能原样通过 ——\n // 不是钳位,是对 -1 的特殊处理)。PointerEvent 构造器则保留 -1。\n // 所以 mouse 类事件必须在构造后把 -1 盖回去,否则「移动=左键按下」的坑\n // 只在 pointer 路径修好、mouse 路径依旧(2517518192 恰好走 pointer,\n // 光看它会误以为已经修完)。\n var needsButtonPatch = init.button < 0;\n var ev = null;\n if (isPointer) {\n init.pointerId = 1;\n init.pointerType = "mouse";\n init.isPrimary = true;\n init.width = 1;\n init.height = 1;\n init.pressure = init.buttons ? 0.5 : 0;\n try {\n if (typeof w.PointerEvent === "function") ev = new w.PointerEvent(type, init);\n } catch (_) {\n /* 退回 MouseEvent */\n }\n }\n if (!ev) {\n try {\n if (typeof w.MouseEvent === "function") ev = new w.MouseEvent(type, init);\n } catch (_) {\n /* 忽略 */\n }\n }\n if (ev && needsButtonPatch && ev.button !== init.button) {\n try {\n Object.defineProperty(ev, "button", { configurable: true, get: function () {\n return init.button;\n } });\n } catch (_) {\n /* 只读且不可重定义时保持构造值 */\n }\n }\n return ev;\n }\n\n function ptrDispatch(node, type, x, y, opts) {\n if (!node || typeof node.dispatchEvent !== "function") return;\n var ev = ptrMakeEvent(type, x, y, opts);\n if (!ev) return;\n try {\n node.dispatchEvent(ev);\n } catch (_) {\n /* 作者处理器抛错不打断后续事件(与官方 CEF 一致:一个坏 listener 不该\n 让整条链断掉,否则 leave 发不出去会留下永久 hover/按下态) */\n }\n }\n\n /** 命中元素变化时补 out/leave + over/enter 四段,顺序与浏览器一致。 */\n function ptrCrossBoundary(prev, next, x, y) {\n if (prev === next) return;\n var ancestor = ptrCommonAncestor(prev, next);\n if (prev) {\n ptrDispatch(prev, "pointerout", x, y, { relatedTarget: next });\n ptrDispatch(prev, "mouseout", x, y, { relatedTarget: next });\n var leaving = ptrChain(prev);\n for (var i = 0; i < leaving.length; i++) {\n if (leaving[i] === ancestor) break;\n // leave 不冒泡:必须逐个发,且 target 就是它自己\n ptrDispatch(leaving[i], "pointerleave", x, y, {\n bubbles: false,\n cancelable: false,\n relatedTarget: next,\n });\n ptrDispatch(leaving[i], "mouseleave", x, y, {\n bubbles: false,\n cancelable: false,\n relatedTarget: next,\n });\n }\n }\n if (next) {\n ptrDispatch(next, "pointerover", x, y, { relatedTarget: prev });\n ptrDispatch(next, "mouseover", x, y, { relatedTarget: prev });\n var entering = [];\n var chain = ptrChain(next);\n for (var j = 0; j < chain.length; j++) {\n if (chain[j] === ancestor) break;\n entering.push(chain[j]);\n }\n // enter 由外向内(祖先先收到),与浏览器一致\n for (var k = entering.length - 1; k >= 0; k--) {\n ptrDispatch(entering[k], "pointerenter", x, y, {\n bubbles: false,\n cancelable: false,\n relatedTarget: prev,\n });\n ptrDispatch(entering[k], "mouseenter", x, y, {\n bubbles: false,\n cancelable: false,\n relatedTarget: prev,\n });\n }\n }\n }\n\n /**\n * 外部指针注入入口。\n *\n * @param {number} x 相对 iframe 视口左边的 **CSS 像素**(= clientX 空间)\n * @param {number} y 同上,相对上边,Y 朝下\n * @param {number} [buttons] 按键位掩码,bit0 左键。与场景通道同一约定,\n * 当前只消费 bit0(右/中键位保留;桌面右键属于 Finder,不该被壁纸劫持)\n *\n * 接**像素**而不是归一化坐标:网页壁纸的 iframe 在 cover 露底自适配下可能比舞台大\n * 并带居中偏移(见 web.ts installLetterboxFix),换算需要 iframe 的几何 —— 那是父页\n * 才知道的信息,父页换算完再推进来,shim 不做二次除法。\n *\n * 暂停期间丢弃:官方暂停语义是「冻结渲染进程」,此时派发事件会让作者的动画状态\n * 在冻结中继续推进,恢复时画面跳一下。\n */\n w.__wePushPointer = function (x, y, buttons) {\n if (paused) return;\n var nx = Number(x);\n var ny = Number(y);\n // 非有限值直接丢弃(与场景通道同一约定):NaN 传进 clientX 会让 elementFromPoint\n // 返回 null、后续 offsetX 全成 NaN,作者的位移积分会一次性污染成 NaN 且不报错。\n if (!isFinite(nx) || !isFinite(ny)) return;\n var mask = Number(buttons) || 0;\n var moved = !ptrHas || nx !== ptrX || ny !== ptrY;\n var maskChanged = mask !== ptrButtons;\n // 位置与按键都没变就什么都不发:宿主按 ~90Hz 推送,静止时重复派发\n // mousemove 会让作者的「有没有在动」判定(1081733658 网格)永远认为在动。\n if (!moved && !maskChanged) return;\n\n var dx = ptrHas ? nx - ptrX : 0;\n var dy = ptrHas ? ny - ptrY : 0;\n ptrX = nx;\n ptrY = ny;\n ptrHas = true;\n\n var target = ptrHitTest(nx, ny);\n if (moved) {\n ptrCrossBoundary(ptrTarget, target, nx, ny);\n ptrTarget = target;\n ptrDispatch(target, "pointermove", nx, ny, { movementX: dx, movementY: dy });\n ptrDispatch(target, "mousemove", nx, ny, { movementX: dx, movementY: dy });\n } else {\n ptrTarget = target;\n }\n\n if (!maskChanged) return;\n var wasDown = (ptrButtons & 1) !== 0;\n var isDown = (mask & 1) !== 0;\n ptrButtons = mask;\n if (isDown === wasDown) return; // 只有高位变化:当前不消费\n if (isDown) {\n ptrDownTarget = target;\n ptrDispatch(target, "pointerdown", nx, ny, { button: 0, detail: 1 });\n ptrDispatch(target, "mousedown", nx, ny, { button: 0, detail: 1 });\n return;\n }\n ptrDispatch(target, "pointerup", nx, ny, { button: 0, detail: 1 });\n ptrDispatch(target, "mouseup", nx, ny, { button: 0, detail: 1 });\n // click 只在 down/up 落在同一元素上时发(否则是拖拽,浏览器也不发)\n if (ptrDownTarget && ptrDownTarget === target) {\n var now = Date.now();\n var isDouble =\n ptrLastClickTarget === target && now - ptrLastClickTime <= PTR_DBLCLICK_MS;\n ptrDispatch(target, "click", nx, ny, { button: 0, detail: isDouble ? 2 : 1 });\n if (isDouble) {\n ptrDispatch(target, "dblclick", nx, ny, { button: 0, detail: 2 });\n ptrLastClickTarget = null;\n ptrLastClickTime = 0;\n } else {\n ptrLastClickTarget = target;\n ptrLastClickTime = now;\n }\n }\n ptrDownTarget = null;\n };\n\n /**\n * 指针离开本窗口(鼠标去了别的显示器)。\n *\n * 与场景通道不同,这里**必须把 out/leave 链发出去**:场景侧只是清一个状态位,\n * 而网页作者的 hover 态是自己记的,不发 leave 就永久卡在「鼠标还在上面」\n * (1081733658 网格会一直跑、1748506393 的 `pointers[0].down` 一直为 true)。\n * 按下态也要补一次 up,否则拖拽逻辑永远不结束。\n */\n w.__wePointerLeave = function () {\n if ((ptrButtons & 1) !== 0 && ptrTarget) {\n ptrDispatch(ptrTarget, "pointerup", ptrX, ptrY, { button: 0, buttons: 0, detail: 1 });\n ptrDispatch(ptrTarget, "mouseup", ptrX, ptrY, { button: 0, buttons: 0, detail: 1 });\n }\n ptrButtons = 0;\n ptrDownTarget = null;\n if (ptrTarget) {\n ptrCrossBoundary(ptrTarget, null, ptrX, ptrY);\n ptrTarget = null;\n }\n // 位置(ptrX/ptrY)与 ptrHas 保留:下次进来时 movement 才是真实位移,\n // 而不是从 (0,0) 跳过来的一个巨大假 delta。\n };\n\n // —— rAF 节流(带 __weThrottled,避免父页 injectGpuThrottle 双层减半)——\n\n function installRafThrottle() {\n var throttled = function (cb) {\n if (typeof cb !== "function") return 0;\n if (paused) {\n var idHold = ++rafCounter;\n rafMap[idHold] = { kind: "hold", cb: cb };\n return idHold;\n }\n var limit = fps >= 60 ? 0 : 1000 / fps;\n if (limit <= 0) {\n var idNative = origRaf(function (now) {\n delete rafMap[idNative];\n try {\n cb(now);\n } catch (_) {\n /* 忽略 */\n }\n try {\n w.parent.postMessage({ op: "we-frame", t: now }, "*");\n } catch (_) {\n /* 忽略 */\n }\n });\n rafMap[idNative] = { kind: "native", id: idNative };\n return idNative;\n }\n var id = ++rafCounter;\n var to = w.setTimeout(function () {\n delete rafMap[id];\n origRaf(function (now) {\n try {\n cb(now);\n } catch (_) {\n /* 忽略 */\n }\n try {\n w.parent.postMessage({ op: "we-frame", t: now }, "*");\n } catch (_) {\n /* 忽略 */\n }\n });\n }, limit);\n rafMap[id] = { kind: "timeout", to: to };\n return id;\n };\n throttled.__weThrottled = true;\n w.requestAnimationFrame = throttled;\n w.cancelAnimationFrame = function (id) {\n var ent = rafMap[id];\n if (!ent) {\n try {\n origCaf(id);\n } catch (_) {\n /* 忽略 */\n }\n return;\n }\n delete rafMap[id];\n if (ent.kind === "timeout") w.clearTimeout(ent.to);\n else if (ent.kind === "native") origCaf(ent.id);\n };\n }\n\n installRafThrottle();\n})(window);\n\n';
|
|
15064
|
+
function weShimCall(rt, call) {
|
|
15065
|
+
try {
|
|
15066
|
+
const win = rt.iframe?.contentWindow;
|
|
15067
|
+
if (win) call(win);
|
|
15068
|
+
} catch {
|
|
15069
|
+
}
|
|
15070
|
+
}
|
|
15071
|
+
function injectGpuThrottle(rt, f, _doc) {
|
|
15072
|
+
const win = f.contentWindow;
|
|
15073
|
+
if (!win) return;
|
|
15074
|
+
if (win.requestAnimationFrame?.__weThrottled) return;
|
|
15075
|
+
const fps = rt.cfg.sceneFps || 30;
|
|
15076
|
+
if (fps >= 60) return;
|
|
15077
|
+
const interval = 1e3 / fps;
|
|
15078
|
+
try {
|
|
15079
|
+
const origRaf = win.requestAnimationFrame.bind(win);
|
|
15080
|
+
const rafMap = /* @__PURE__ */ new Map();
|
|
15081
|
+
let counter = 0;
|
|
15082
|
+
win.requestAnimationFrame = (cb) => {
|
|
15083
|
+
const id = ++counter;
|
|
15084
|
+
const to = win.setTimeout(() => {
|
|
15085
|
+
rafMap.delete(id);
|
|
15086
|
+
origRaf((now) => {
|
|
15087
|
+
try {
|
|
15088
|
+
cb(now);
|
|
15089
|
+
} catch {
|
|
15090
|
+
}
|
|
15091
|
+
});
|
|
15092
|
+
}, interval);
|
|
15093
|
+
rafMap.set(id, to);
|
|
15094
|
+
return id;
|
|
15095
|
+
};
|
|
15096
|
+
win.cancelAnimationFrame = (id) => {
|
|
15097
|
+
const to = rafMap.get(id);
|
|
15098
|
+
if (to !== void 0) {
|
|
15099
|
+
win.clearTimeout(to);
|
|
15100
|
+
rafMap.delete(id);
|
|
15101
|
+
}
|
|
15102
|
+
};
|
|
15103
|
+
} catch {
|
|
15104
|
+
}
|
|
15105
|
+
}
|
|
15106
|
+
const pumpBuffer = new Float32Array(128);
|
|
15107
|
+
function packWebAudioArrayInto(out, left, right) {
|
|
15108
|
+
const nL = Math.min(64, left.length);
|
|
15109
|
+
const nR = Math.min(64, right.length);
|
|
15110
|
+
for (let i = 0; i < nL; i++) out[i] = Number(left[i]) || 0;
|
|
15111
|
+
for (let i = 0; i < nR; i++) out[64 + i] = Number(right[i]) || 0;
|
|
15112
|
+
return out;
|
|
15113
|
+
}
|
|
15114
|
+
const WEB_SIM_AUDIO_GAIN = 1.8;
|
|
15115
|
+
const WEB_SIM_AUDIO_GAMMA = 1.8;
|
|
15116
|
+
const WEB_AUDIO_PUMP_HZ = 30;
|
|
15117
|
+
function shapeWebAudioBand(pre) {
|
|
15118
|
+
const v = Number(pre) || 0;
|
|
15119
|
+
if (v <= 0) return 0;
|
|
15120
|
+
return Math.min(1, Math.pow(v, WEB_SIM_AUDIO_GAMMA) * WEB_SIM_AUDIO_GAIN);
|
|
15121
|
+
}
|
|
15122
|
+
function defaultAudioDriver() {
|
|
15123
|
+
const sim = createSimulatedAudio();
|
|
15124
|
+
const left = new Float32Array(64);
|
|
15125
|
+
const right = new Float32Array(64);
|
|
15126
|
+
return {
|
|
15127
|
+
tick(nowMs) {
|
|
15128
|
+
sim.update(nowMs / 1e3);
|
|
15129
|
+
},
|
|
15130
|
+
snapshot() {
|
|
15131
|
+
const s = sim.snapshot;
|
|
15132
|
+
const preL = s.preL64;
|
|
15133
|
+
const preR = s.preR64;
|
|
15134
|
+
for (let i = 0; i < 64; i++) {
|
|
15135
|
+
if (preL && preR) {
|
|
15136
|
+
left[i] = shapeWebAudioBand(preL[i]);
|
|
15137
|
+
right[i] = shapeWebAudioBand(preR[i]);
|
|
15138
|
+
} else {
|
|
15139
|
+
left[i] = (Number(s.left64[i]) || 0) * 0.2;
|
|
15140
|
+
right[i] = (Number(s.right64[i]) || 0) * 0.2;
|
|
15141
|
+
}
|
|
15142
|
+
}
|
|
15143
|
+
return { left, right };
|
|
15144
|
+
}
|
|
15145
|
+
};
|
|
15146
|
+
}
|
|
15147
|
+
function resolveContainer(rt, cfg) {
|
|
15148
|
+
if (rt.wrap) return rt.wrap;
|
|
15149
|
+
const el = cfg.canvas;
|
|
15150
|
+
if (!el) return null;
|
|
15151
|
+
if (el instanceof HTMLCanvasElement) {
|
|
15152
|
+
const parent = el.parentElement;
|
|
15153
|
+
if (parent) {
|
|
15154
|
+
reportDiag(rt, cfg, "网页壁纸挂在 canvas 父容器上(canvas 不能有子节点;更适合空 div)");
|
|
15155
|
+
return parent;
|
|
15156
|
+
}
|
|
15157
|
+
return null;
|
|
15158
|
+
}
|
|
15159
|
+
return el;
|
|
15160
|
+
}
|
|
15161
|
+
function buildSeedScript(props, fps, volume) {
|
|
15162
|
+
const parts = [];
|
|
15163
|
+
if (fps != null && Number.isFinite(fps)) parts.push(`window.__weSetFps(${Number(fps)});`);
|
|
15164
|
+
if (volume != null && Number.isFinite(volume)) {
|
|
15165
|
+
parts.push(`window.__weSetVolume(${Math.max(0, Math.min(1, Number(volume)))});`);
|
|
15166
|
+
}
|
|
15167
|
+
if (props && Object.keys(props).length) {
|
|
15168
|
+
parts.push(`window.__weSeedProps(${JSON.stringify(props)});`);
|
|
15169
|
+
}
|
|
15170
|
+
return parts.join("\n");
|
|
15171
|
+
}
|
|
15172
|
+
function installLetterboxFix(rt, f, container) {
|
|
15173
|
+
const BASE = "position:absolute;border:none;background:transparent;";
|
|
15174
|
+
const applyFull = () => {
|
|
15175
|
+
f.style.cssText = BASE + "inset:0;width:100%;height:100%;";
|
|
15176
|
+
};
|
|
15177
|
+
applyFull();
|
|
15178
|
+
let lastKey = "";
|
|
15179
|
+
const relayout = () => {
|
|
15180
|
+
if (!f.isConnected) return;
|
|
15181
|
+
let doc = null;
|
|
15182
|
+
try {
|
|
15183
|
+
doc = f.contentDocument;
|
|
15184
|
+
} catch {
|
|
15185
|
+
return;
|
|
15186
|
+
}
|
|
15187
|
+
if (!doc) return;
|
|
15188
|
+
const stageW = container.clientWidth || window.innerWidth || 0;
|
|
15189
|
+
const stageH = container.clientHeight || window.innerHeight || 0;
|
|
15190
|
+
const cover = normalizeFit(rt.cfg.fit) === "cover";
|
|
15191
|
+
applyFull();
|
|
15192
|
+
const box = cover && stageW > 0 && stageH > 0 ? measureWebLetterbox(doc) : null;
|
|
15193
|
+
const vp = box ? webCoverViewport(stageW, stageH, box.contentAspect) : null;
|
|
15194
|
+
const key = vp ? `${Math.round(vp.width)}x${Math.round(vp.height)}` : "full";
|
|
15195
|
+
if (!vp) {
|
|
15196
|
+
lastKey = "full";
|
|
15197
|
+
return;
|
|
15198
|
+
}
|
|
15199
|
+
f.style.cssText = BASE + `left:${vp.left}px;top:${vp.top}px;width:${vp.width}px;height:${vp.height}px;`;
|
|
15200
|
+
if (key !== lastKey) {
|
|
15201
|
+
lastKey = key;
|
|
15202
|
+
reportDiag(
|
|
15203
|
+
rt,
|
|
15204
|
+
rt.cfg,
|
|
15205
|
+
`网页壁纸露底自适配:视口按内容比例改为 ${Math.round(vp.width)}×${Math.round(vp.height)}(cover 居中裁切)`
|
|
15206
|
+
);
|
|
15207
|
+
}
|
|
15208
|
+
};
|
|
15209
|
+
const onResize = () => relayout();
|
|
15210
|
+
window.addEventListener("resize", onResize);
|
|
15211
|
+
let ro;
|
|
15212
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
15213
|
+
ro = new ResizeObserver(() => relayout());
|
|
15214
|
+
ro.observe(container);
|
|
15215
|
+
}
|
|
15216
|
+
const timers = [];
|
|
15217
|
+
const onLoad = () => {
|
|
15218
|
+
relayout();
|
|
15219
|
+
for (const d of [120, 400, 1200]) timers.push(window.setTimeout(relayout, d));
|
|
15220
|
+
try {
|
|
15221
|
+
const doc = f.contentDocument;
|
|
15222
|
+
if (doc) {
|
|
15223
|
+
for (const el of doc.querySelectorAll("video,img")) {
|
|
15224
|
+
el.addEventListener("loadedmetadata", relayout, { once: true });
|
|
15225
|
+
el.addEventListener("load", relayout, { once: true });
|
|
15226
|
+
}
|
|
15227
|
+
}
|
|
15228
|
+
} catch {
|
|
15229
|
+
}
|
|
15230
|
+
};
|
|
15231
|
+
f.addEventListener("load", onLoad);
|
|
15232
|
+
rt.webRelayout = relayout;
|
|
15233
|
+
const prev = rt.sceneCleanup;
|
|
15234
|
+
rt.sceneCleanup = () => {
|
|
15235
|
+
window.removeEventListener("resize", onResize);
|
|
15236
|
+
ro?.disconnect();
|
|
15237
|
+
for (const t of timers) clearTimeout(t);
|
|
15238
|
+
f.removeEventListener("load", onLoad);
|
|
15239
|
+
if (rt.webRelayout === relayout) rt.webRelayout = void 0;
|
|
15240
|
+
try {
|
|
15241
|
+
prev?.();
|
|
15242
|
+
} catch {
|
|
15243
|
+
}
|
|
15244
|
+
};
|
|
15245
|
+
}
|
|
15246
|
+
function webPointerToClient(u, v, stage, frame, client) {
|
|
15247
|
+
if (!Number.isFinite(u) || !Number.isFinite(v)) return null;
|
|
15248
|
+
if (!(stage.width > 0) || !(stage.height > 0)) return null;
|
|
15249
|
+
const sx = frame.width > 0 && client.width > 0 ? frame.width / client.width : 1;
|
|
15250
|
+
const sy = frame.height > 0 && client.height > 0 ? frame.height / client.height : 1;
|
|
15251
|
+
return {
|
|
15252
|
+
x: (u * stage.width - (frame.left - stage.left)) / (sx || 1),
|
|
15253
|
+
y: (v * stage.height - (frame.top - stage.top)) / (sy || 1)
|
|
15254
|
+
};
|
|
15255
|
+
}
|
|
15256
|
+
function installWebPointerBridge(rt, f, container) {
|
|
15257
|
+
rt.pointerCtl = {
|
|
15258
|
+
push(p) {
|
|
15259
|
+
if (!f.isConnected) return;
|
|
15260
|
+
const cRect = container.getBoundingClientRect();
|
|
15261
|
+
const fRect = f.getBoundingClientRect();
|
|
15262
|
+
const pt = webPointerToClient(
|
|
15263
|
+
Number(p?.u),
|
|
15264
|
+
Number(p?.v),
|
|
15265
|
+
{
|
|
15266
|
+
left: cRect.left,
|
|
15267
|
+
top: cRect.top,
|
|
15268
|
+
width: cRect.width || container.clientWidth || window.innerWidth || 0,
|
|
15269
|
+
height: cRect.height || container.clientHeight || window.innerHeight || 0
|
|
15270
|
+
},
|
|
15271
|
+
{ left: fRect.left, top: fRect.top, width: fRect.width, height: fRect.height },
|
|
15272
|
+
{ width: f.clientWidth, height: f.clientHeight }
|
|
15273
|
+
);
|
|
15274
|
+
if (!pt) return;
|
|
15275
|
+
weShimCall(rt, (w) => w.__wePushPointer?.(pt.x, pt.y, Number(p.buttons) || 0));
|
|
15276
|
+
},
|
|
15277
|
+
leave() {
|
|
15278
|
+
weShimCall(rt, (w) => w.__wePointerLeave?.());
|
|
15279
|
+
}
|
|
15280
|
+
};
|
|
15281
|
+
}
|
|
15282
|
+
function attachIframe(rt, cfg, container, src, opts) {
|
|
15283
|
+
const f = document.createElement("iframe");
|
|
15284
|
+
f.setAttribute("sandbox", "allow-scripts allow-same-origin");
|
|
15285
|
+
f.style.cssText = "position:absolute;inset:0;width:100%;height:100%;border:none;background:transparent;";
|
|
15286
|
+
if (!rt.wrap && getComputedStyle(container).position === "static") {
|
|
15287
|
+
container.style.position = "relative";
|
|
15288
|
+
}
|
|
15289
|
+
f.src = src;
|
|
15290
|
+
container.appendChild(f);
|
|
15291
|
+
rt.iframe = f;
|
|
15292
|
+
if (opts.blobUrl) {
|
|
15293
|
+
(rt.objectUrls ??= []).push(opts.blobUrl);
|
|
15294
|
+
}
|
|
15295
|
+
installLetterboxFix(rt, f, container);
|
|
15296
|
+
if (opts.injected) installWebPointerBridge(rt, f, container);
|
|
15297
|
+
const onFrameMsg = (ev) => {
|
|
15298
|
+
if (ev.source !== f.contentWindow) return;
|
|
15299
|
+
const data = ev.data;
|
|
15300
|
+
if (!data || data.op !== "we-frame") return;
|
|
15301
|
+
if (rt.paused) return;
|
|
15302
|
+
const t = typeof data.t === "number" ? data.t : performance.now();
|
|
15303
|
+
if (opts.frameClock) opts.frameClock.last = t;
|
|
15304
|
+
markFrame(rt, t);
|
|
15305
|
+
};
|
|
15306
|
+
window.addEventListener("message", onFrameMsg);
|
|
15307
|
+
const prevCleanup = rt.sceneCleanup;
|
|
15308
|
+
rt.sceneCleanup = () => {
|
|
15309
|
+
window.removeEventListener("message", onFrameMsg);
|
|
15310
|
+
try {
|
|
15311
|
+
prevCleanup?.();
|
|
15312
|
+
} catch {
|
|
15313
|
+
}
|
|
15314
|
+
};
|
|
15315
|
+
f.addEventListener("load", () => {
|
|
15316
|
+
try {
|
|
15317
|
+
const doc = f.contentDocument;
|
|
15318
|
+
if (doc) window.__blockContextMenu?.(doc);
|
|
15319
|
+
if (!opts.injected) injectGpuThrottle(rt, f, doc);
|
|
15320
|
+
} catch {
|
|
15321
|
+
}
|
|
15322
|
+
weShimCall(rt, (w2) => {
|
|
15323
|
+
const wire = {};
|
|
15324
|
+
for (const [k, v] of Object.entries(rt.liveUserProps ?? {})) wire[k] = { value: v };
|
|
15325
|
+
w2.__weApplyProps?.(wire);
|
|
15326
|
+
w2.__weSetFps?.(rt.cfg.sceneFps ?? 60);
|
|
15327
|
+
w2.__weSetVolume?.(rt.cfg.muted === false ? 1 : 0);
|
|
15328
|
+
if (rt.paused) w2.__weSetPaused?.(true);
|
|
15329
|
+
});
|
|
15330
|
+
try {
|
|
15331
|
+
rt.onFirstFrame?.();
|
|
15332
|
+
rt.onFirstFrame = void 0;
|
|
15333
|
+
} catch {
|
|
15334
|
+
}
|
|
15335
|
+
const w = container.clientWidth || window.innerWidth || 1;
|
|
15336
|
+
const h = container.clientHeight || window.innerHeight || 1;
|
|
15337
|
+
try {
|
|
15338
|
+
rt.onSceneInfo?.({
|
|
15339
|
+
width: w,
|
|
15340
|
+
height: h,
|
|
15341
|
+
layerCount: 0,
|
|
15342
|
+
hasModels: false,
|
|
15343
|
+
hasParticles: false,
|
|
15344
|
+
hasText: false
|
|
15345
|
+
});
|
|
15346
|
+
} catch {
|
|
15347
|
+
}
|
|
15348
|
+
});
|
|
15349
|
+
}
|
|
15350
|
+
const WEB_ASPECT_EPS = 5e-3;
|
|
15351
|
+
const WEB_LETTERBOX_MIN_RATIO = 0.01;
|
|
15352
|
+
const WEB_ASPECT_MIN = 0.2;
|
|
15353
|
+
const WEB_ASPECT_MAX = 6;
|
|
15354
|
+
function webCoverViewport(stageW, stageH, contentAspect) {
|
|
15355
|
+
if (!(stageW > 0) || !(stageH > 0) || !(contentAspect > 0)) return null;
|
|
15356
|
+
const stageAspect = stageW / stageH;
|
|
15357
|
+
if (Math.abs(stageAspect - contentAspect) <= WEB_ASPECT_EPS) return null;
|
|
15358
|
+
if (stageAspect < contentAspect) {
|
|
15359
|
+
const width = stageH * contentAspect;
|
|
15360
|
+
return { width, height: stageH, left: (stageW - width) / 2, top: 0 };
|
|
15361
|
+
}
|
|
15362
|
+
const height = stageW / contentAspect;
|
|
15363
|
+
return { width: stageW, height, left: 0, top: (stageH - height) / 2 };
|
|
15364
|
+
}
|
|
15365
|
+
function measureWebLetterbox(doc) {
|
|
15366
|
+
const win = doc.defaultView;
|
|
15367
|
+
if (!win) return null;
|
|
15368
|
+
const vw = win.innerWidth;
|
|
15369
|
+
const vh = win.innerHeight;
|
|
15370
|
+
if (!(vw > 0) || !(vh > 0)) return null;
|
|
15371
|
+
const cands = [...doc.querySelectorAll("video,img")];
|
|
15372
|
+
for (const el of cands) {
|
|
15373
|
+
const r = el.getBoundingClientRect();
|
|
15374
|
+
if (r.width <= 0 || r.height <= 0) continue;
|
|
15375
|
+
if (r.width < vw * 0.98) continue;
|
|
15376
|
+
if (Math.abs(r.left) > vw * 0.02 || r.top > vh * 0.02) continue;
|
|
15377
|
+
if (vh - r.height < vh * WEB_LETTERBOX_MIN_RATIO) continue;
|
|
15378
|
+
const natW = el.videoWidth || el.naturalWidth || 0;
|
|
15379
|
+
const natH = el.videoHeight || el.naturalHeight || 0;
|
|
15380
|
+
if (!(natW > 0) || !(natH > 0)) continue;
|
|
15381
|
+
const aspect = natW / natH;
|
|
15382
|
+
if (!Number.isFinite(aspect) || aspect < WEB_ASPECT_MIN || aspect > WEB_ASPECT_MAX) continue;
|
|
15383
|
+
return { contentAspect: aspect };
|
|
15384
|
+
}
|
|
15385
|
+
return null;
|
|
15386
|
+
}
|
|
15387
|
+
function vecToCss(v) {
|
|
15388
|
+
if (!v) return "rgb(128,128,128)";
|
|
15389
|
+
const r = Math.round(Math.max(0, Math.min(1, Number(v.x) || 0)) * 255);
|
|
15390
|
+
const g = Math.round(Math.max(0, Math.min(1, Number(v.y) || 0)) * 255);
|
|
15391
|
+
const b = Math.round(Math.max(0, Math.min(1, Number(v.z) || 0)) * 255);
|
|
15392
|
+
return `rgb(${r},${g},${b})`;
|
|
15393
|
+
}
|
|
15394
|
+
function thumbDataUrlFromSnap(snap) {
|
|
15395
|
+
try {
|
|
15396
|
+
const c = document.createElement("canvas");
|
|
15397
|
+
c.width = c.height = 64;
|
|
15398
|
+
const ctx = c.getContext("2d");
|
|
15399
|
+
if (!ctx) return "";
|
|
15400
|
+
const p = snap.primaryColor;
|
|
15401
|
+
const s = snap.secondaryColor;
|
|
15402
|
+
const grd = ctx.createLinearGradient(0, 0, 64, 64);
|
|
15403
|
+
grd.addColorStop(0, vecToCss(p));
|
|
15404
|
+
grd.addColorStop(1, vecToCss(s));
|
|
15405
|
+
ctx.fillStyle = grd;
|
|
15406
|
+
ctx.fillRect(0, 0, 64, 64);
|
|
15407
|
+
return c.toDataURL("image/jpeg", 0.85);
|
|
15408
|
+
} catch {
|
|
15409
|
+
return "";
|
|
15410
|
+
}
|
|
15411
|
+
}
|
|
15412
|
+
function defaultMediaDriver() {
|
|
15413
|
+
return media.createSimulatedMedia();
|
|
15414
|
+
}
|
|
15415
|
+
function pushMediaDiff(rt, prev, snap) {
|
|
15416
|
+
const events = media.diffMediaEvents(prev, snap);
|
|
15417
|
+
for (const { name, event } of events) {
|
|
15418
|
+
if (name === "mediaStatusChanged") {
|
|
15419
|
+
weShimCall(rt, (w) => w.__wePushMedia?.({ op: "status", enabled: !!event.enabled }));
|
|
15420
|
+
} else if (name === "mediaPropertiesChanged") {
|
|
15421
|
+
weShimCall(
|
|
15422
|
+
rt,
|
|
15423
|
+
(w) => w.__wePushMedia?.({
|
|
15424
|
+
op: "properties",
|
|
15425
|
+
title: event.title ?? "",
|
|
15426
|
+
artist: event.artist ?? "",
|
|
15427
|
+
album: event.album ?? "",
|
|
15428
|
+
albumArtist: event.albumArtist ?? ""
|
|
15429
|
+
})
|
|
15430
|
+
);
|
|
15431
|
+
} else if (name === "mediaThumbnailChanged") {
|
|
15432
|
+
const thumb = thumbDataUrlFromSnap(snap);
|
|
15433
|
+
weShimCall(
|
|
15434
|
+
rt,
|
|
15435
|
+
(w) => w.__wePushMedia?.({
|
|
15436
|
+
op: "thumbnail",
|
|
15437
|
+
thumbnail: thumb,
|
|
15438
|
+
hasThumbnail: !!event.hasThumbnail || !!thumb,
|
|
15439
|
+
primaryColor: vecToCss(event.primaryColor),
|
|
15440
|
+
secondaryColor: vecToCss(event.secondaryColor),
|
|
15441
|
+
tertiaryColor: vecToCss(event.tertiaryColor),
|
|
15442
|
+
textColor: vecToCss(event.textColor),
|
|
15443
|
+
highContrastColor: vecToCss(event.highContrastColor)
|
|
15444
|
+
})
|
|
15445
|
+
);
|
|
15446
|
+
} else if (name === "mediaPlaybackChanged") {
|
|
15447
|
+
weShimCall(rt, (w) => w.__wePushMedia?.({ op: "playback", state: Number(event.state) || 0 }));
|
|
15448
|
+
} else if (name === "mediaTimelineChanged") {
|
|
15449
|
+
weShimCall(
|
|
15450
|
+
rt,
|
|
15451
|
+
(w) => w.__wePushMedia?.({
|
|
15452
|
+
op: "timeline",
|
|
15453
|
+
position: Number(event.position) || 0,
|
|
15454
|
+
duration: Number(event.duration) || 0
|
|
15455
|
+
})
|
|
15456
|
+
);
|
|
15457
|
+
}
|
|
15458
|
+
}
|
|
15459
|
+
return media.cloneMediaSnapshot(snap);
|
|
15460
|
+
}
|
|
15461
|
+
function startAudioPump(rt, driver, frameClock) {
|
|
15462
|
+
if (!driver) return;
|
|
15463
|
+
let raf = 0;
|
|
15464
|
+
let lastPush = 0;
|
|
15465
|
+
const tick = (now) => {
|
|
15466
|
+
raf = requestAnimationFrame(tick);
|
|
15467
|
+
if (rt.paused || !rt.iframe) return;
|
|
15468
|
+
const fps = rt.cfg.sceneFps || 60;
|
|
15469
|
+
const pumpFps = Math.min(Math.max(1, fps), WEB_AUDIO_PUMP_HZ);
|
|
15470
|
+
const interval = 1e3 / pumpFps;
|
|
15471
|
+
if (now - lastPush < interval * 0.85) return;
|
|
15472
|
+
lastPush = now;
|
|
15473
|
+
try {
|
|
15474
|
+
driver.tick?.(now);
|
|
15475
|
+
const snap = driver.snapshot();
|
|
15476
|
+
const arr = packWebAudioArrayInto(pumpBuffer, snap.left, snap.right);
|
|
15477
|
+
weShimCall(rt, (w) => w.__wePushAudio?.(arr));
|
|
15478
|
+
if (frameClock && now - frameClock.last > 200) markFrame(rt, now);
|
|
15479
|
+
} catch {
|
|
15480
|
+
}
|
|
15481
|
+
};
|
|
15482
|
+
raf = requestAnimationFrame(tick);
|
|
15483
|
+
const prev = rt.sceneCleanup;
|
|
15484
|
+
rt.sceneCleanup = () => {
|
|
15485
|
+
cancelAnimationFrame(raf);
|
|
15486
|
+
try {
|
|
15487
|
+
prev?.();
|
|
15488
|
+
} catch {
|
|
15489
|
+
}
|
|
15490
|
+
};
|
|
15491
|
+
}
|
|
15492
|
+
function startMediaPump(rt, driver) {
|
|
15493
|
+
if (!driver) return;
|
|
15494
|
+
let raf = 0;
|
|
15495
|
+
let lastMedia = null;
|
|
15496
|
+
let lastTick = 0;
|
|
15497
|
+
const tick = (now) => {
|
|
15498
|
+
raf = requestAnimationFrame(tick);
|
|
15499
|
+
if (rt.paused || !rt.iframe) return;
|
|
15500
|
+
if (now - lastTick < 200) return;
|
|
15501
|
+
lastTick = now;
|
|
15502
|
+
try {
|
|
15503
|
+
driver.update(now / 1e3);
|
|
15504
|
+
lastMedia = pushMediaDiff(rt, lastMedia, driver.snapshot);
|
|
15505
|
+
} catch {
|
|
15506
|
+
}
|
|
15507
|
+
};
|
|
15508
|
+
raf = requestAnimationFrame(tick);
|
|
15509
|
+
const prev = rt.sceneCleanup;
|
|
15510
|
+
rt.sceneCleanup = () => {
|
|
15511
|
+
cancelAnimationFrame(raf);
|
|
15512
|
+
try {
|
|
15513
|
+
prev?.();
|
|
15514
|
+
} catch {
|
|
15515
|
+
}
|
|
15516
|
+
};
|
|
15517
|
+
}
|
|
15518
|
+
function installWebCtl(rt) {
|
|
15519
|
+
rt.sceneCtl = {
|
|
15520
|
+
pause() {
|
|
15521
|
+
rt.paused = true;
|
|
15522
|
+
weShimCall(rt, (w) => w.__weSetPaused?.(true));
|
|
15523
|
+
},
|
|
15524
|
+
resume() {
|
|
15525
|
+
rt.paused = false;
|
|
15526
|
+
weShimCall(rt, (w) => w.__weSetPaused?.(false));
|
|
15527
|
+
},
|
|
15528
|
+
applyUserProperties(props) {
|
|
15529
|
+
const flat = { ...rt.liveUserProps ?? {} };
|
|
15530
|
+
for (const [k, v] of Object.entries(props ?? {})) {
|
|
15531
|
+
const val = v && typeof v === "object" && "value" in v ? v.value : v;
|
|
15532
|
+
flat[k] = val;
|
|
15533
|
+
}
|
|
15534
|
+
rt.liveUserProps = flat;
|
|
15535
|
+
weShimCall(rt, (w) => w.__weApplyProps?.(props));
|
|
15536
|
+
}
|
|
15537
|
+
};
|
|
15538
|
+
}
|
|
15539
|
+
function isSameOriginUrl(url) {
|
|
15540
|
+
try {
|
|
15541
|
+
return new URL(url, location.href).origin === location.origin;
|
|
15542
|
+
} catch {
|
|
15543
|
+
return false;
|
|
15544
|
+
}
|
|
15545
|
+
}
|
|
15546
|
+
function projectPropertiesToWire(project) {
|
|
15547
|
+
const props = project?.general?.properties;
|
|
15548
|
+
if (!props || typeof props !== "object") return {};
|
|
15549
|
+
const out = {};
|
|
15550
|
+
for (const [name, def] of Object.entries(props)) {
|
|
15551
|
+
if (!def || typeof def !== "object" || typeof def.type !== "string") continue;
|
|
15552
|
+
const raw = def.value;
|
|
15553
|
+
const type = def.type.toLowerCase();
|
|
15554
|
+
if (raw === null || raw === void 0) {
|
|
15555
|
+
if (type === "file" || type === "directory") {
|
|
15556
|
+
out[name] = { value: "" };
|
|
15557
|
+
continue;
|
|
15558
|
+
}
|
|
15559
|
+
if (!("value" in def)) continue;
|
|
15560
|
+
}
|
|
15561
|
+
out[name] = { value: raw };
|
|
15562
|
+
}
|
|
15563
|
+
return out;
|
|
15564
|
+
}
|
|
15565
|
+
async function fetchProjectWire(entryUrl) {
|
|
15566
|
+
try {
|
|
15567
|
+
const projUrl = new URL("project.json", new URL(entryUrl, location.href));
|
|
15568
|
+
const r = await fetch(projUrl.href, { credentials: "same-origin" });
|
|
15569
|
+
if (!r.ok) return {};
|
|
15570
|
+
return projectPropertiesToWire(await r.json());
|
|
15571
|
+
} catch {
|
|
15572
|
+
return {};
|
|
15573
|
+
}
|
|
15574
|
+
}
|
|
15575
|
+
function mergeLiveIntoWire(defaults, live) {
|
|
15576
|
+
const out = { ...defaults };
|
|
15577
|
+
if (live) {
|
|
15578
|
+
for (const [k, v] of Object.entries(live)) out[k] = { value: v };
|
|
15579
|
+
}
|
|
15580
|
+
return out;
|
|
15581
|
+
}
|
|
15582
|
+
function mountWeb(rt, cfg) {
|
|
15583
|
+
clear(rt);
|
|
15584
|
+
rt.cfg = cfg;
|
|
15585
|
+
const container = resolveContainer(rt, cfg);
|
|
15586
|
+
if (!container) {
|
|
15587
|
+
reportDiag(rt, cfg, "网页壁纸:无可用容器");
|
|
15588
|
+
rt.onError?.(new Error("网页壁纸:无可用容器"));
|
|
15589
|
+
return;
|
|
15590
|
+
}
|
|
15591
|
+
const entry = cfg.src ?? "";
|
|
15592
|
+
if (!entry) {
|
|
15593
|
+
reportDiag(rt, cfg, "网页壁纸:缺少 src");
|
|
15594
|
+
rt.onError?.(new Error("网页壁纸:缺少 src"));
|
|
15595
|
+
return;
|
|
15596
|
+
}
|
|
15597
|
+
installWebCtl(rt);
|
|
15598
|
+
const cfgExt = cfg;
|
|
15599
|
+
const audioDriver = cfgExt._webAudio === null ? null : cfgExt._webAudio ?? defaultAudioDriver();
|
|
15600
|
+
const mediaDriver = cfgExt._webMedia === null ? null : cfgExt._webMedia ?? defaultMediaDriver();
|
|
15601
|
+
const finishBare = (why) => {
|
|
15602
|
+
reportDiag(rt, cfg, `网页壁纸 shim 注入失败(${why}),退回裸 iframe`);
|
|
15603
|
+
attachIframe(rt, cfg, container, entry, { injected: false });
|
|
15604
|
+
startAudioPump(rt, null);
|
|
15605
|
+
startMediaPump(rt, null);
|
|
15606
|
+
};
|
|
15607
|
+
const frameClock = { last: 0 };
|
|
15608
|
+
const startPumps = () => {
|
|
15609
|
+
startAudioPump(rt, audioDriver, frameClock);
|
|
15610
|
+
startMediaPump(rt, mediaDriver);
|
|
15611
|
+
};
|
|
15612
|
+
void (async () => {
|
|
15613
|
+
const defaults = await fetchProjectWire(entry);
|
|
15614
|
+
const wire = mergeLiveIntoWire(defaults, rt.liveUserProps);
|
|
15615
|
+
rt.liveUserProps = Object.fromEntries(Object.entries(wire).map(([k, w]) => [k, w.value]));
|
|
15616
|
+
if (isSameOriginUrl(entry)) {
|
|
15617
|
+
attachIframe(rt, cfg, container, entry, { injected: true, frameClock });
|
|
15618
|
+
startPumps();
|
|
15619
|
+
const f = rt.iframe;
|
|
15620
|
+
f?.addEventListener(
|
|
15621
|
+
"load",
|
|
15622
|
+
() => {
|
|
15623
|
+
let hasShim = false;
|
|
15624
|
+
weShimCall(rt, (w) => {
|
|
15625
|
+
hasShim = typeof w.__weSetPaused === "function";
|
|
15626
|
+
});
|
|
15627
|
+
if (!hasShim) {
|
|
15628
|
+
reportDiag(
|
|
15629
|
+
rt,
|
|
15630
|
+
cfg,
|
|
15631
|
+
"网页壁纸:同源入口未检测到 WE shim(host 未注入?);Spine 类壁纸请确认 /web/ HTML 改写"
|
|
15632
|
+
);
|
|
15633
|
+
}
|
|
15634
|
+
},
|
|
15635
|
+
{ once: true }
|
|
15636
|
+
);
|
|
15637
|
+
return;
|
|
15638
|
+
}
|
|
15639
|
+
try {
|
|
15640
|
+
const res = await fetch(entry, { credentials: "same-origin" });
|
|
15641
|
+
if (!res.ok) {
|
|
15642
|
+
finishBare(`HTTP ${res.status}`);
|
|
15643
|
+
return;
|
|
15644
|
+
}
|
|
15645
|
+
const html = await res.text();
|
|
15646
|
+
if (hasBlockingCsp(html)) {
|
|
15647
|
+
finishBare("CSP 阻止 inline script");
|
|
15648
|
+
return;
|
|
15649
|
+
}
|
|
15650
|
+
const rewritten = rewriteHtml(html, shimSource, {
|
|
15651
|
+
baseHref: entryDirUrl(entry),
|
|
15652
|
+
seedScript: buildSeedScript(wire, cfg.sceneFps, cfg.muted === false ? 1 : 0)
|
|
15653
|
+
});
|
|
15654
|
+
const blob = new Blob([rewritten], { type: "text/html;charset=utf-8" });
|
|
15655
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
15656
|
+
attachIframe(rt, cfg, container, blobUrl, { blobUrl, injected: true, frameClock });
|
|
15657
|
+
startPumps();
|
|
15658
|
+
} catch (e) {
|
|
15659
|
+
finishBare(e instanceof Error ? e.message : String(e));
|
|
15660
|
+
}
|
|
15661
|
+
})();
|
|
15662
|
+
}
|
|
14326
15663
|
function mountWallpaper(rt, cfg) {
|
|
14327
|
-
|
|
15664
|
+
const type = String(cfg.type ?? "").toLowerCase();
|
|
15665
|
+
cfg = { ...cfg, type };
|
|
15666
|
+
rt.cfg = cfg;
|
|
15667
|
+
if ((type === "video" || type === "gif" || type === "image") && cfg.src) {
|
|
14328
15668
|
mountMedia(rt, cfg);
|
|
14329
|
-
} else if (
|
|
15669
|
+
} else if (type === "scene" && (cfg.source || cfg.src)) {
|
|
14330
15670
|
mountScene(rt, cfg);
|
|
15671
|
+
} else if (type === "web" && cfg.src) {
|
|
15672
|
+
mountWeb(rt, cfg);
|
|
14331
15673
|
} else {
|
|
14332
15674
|
rt.onUnhandledType?.(cfg);
|
|
14333
15675
|
}
|
|
@@ -14337,22 +15679,60 @@ function normalizeFitOption(fit) {
|
|
|
14337
15679
|
if (fit === "fill") return "cover";
|
|
14338
15680
|
return fit === "contain" || fit === "stretch" ? fit : "cover";
|
|
14339
15681
|
}
|
|
14340
|
-
function
|
|
14341
|
-
|
|
14342
|
-
|
|
14343
|
-
|
|
14344
|
-
|
|
15682
|
+
function isWebProject(project) {
|
|
15683
|
+
const t = project?.type;
|
|
15684
|
+
return typeof t === "string" && t.toLowerCase() === "web";
|
|
15685
|
+
}
|
|
15686
|
+
function ensureSceneCanvas(el) {
|
|
15687
|
+
if (el instanceof HTMLCanvasElement) return el;
|
|
15688
|
+
const existing = el.querySelector(":scope > canvas[data-webwallgl]");
|
|
15689
|
+
if (existing instanceof HTMLCanvasElement) return existing;
|
|
15690
|
+
const c = document.createElement("canvas");
|
|
15691
|
+
c.setAttribute("data-webwallgl", "1");
|
|
15692
|
+
c.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;";
|
|
15693
|
+
if (getComputedStyle(el).position === "static") el.style.position = "relative";
|
|
15694
|
+
el.appendChild(c);
|
|
15695
|
+
return c;
|
|
15696
|
+
}
|
|
15697
|
+
async function resolveMountConfig(el, o) {
|
|
15698
|
+
const base = {
|
|
14345
15699
|
fit: normalizeFitOption(o.fit),
|
|
14346
15700
|
renderDpr: o.renderDpr ?? 1,
|
|
14347
15701
|
sceneFps: o.fps ?? 60,
|
|
14348
15702
|
muted: (o.volume ?? 0) <= 0,
|
|
14349
|
-
loop: true
|
|
15703
|
+
loop: true,
|
|
15704
|
+
canvas: el,
|
|
15705
|
+
source: o.source
|
|
14350
15706
|
};
|
|
15707
|
+
let project = null;
|
|
15708
|
+
try {
|
|
15709
|
+
project = await o.source.project?.() ?? null;
|
|
15710
|
+
} catch {
|
|
15711
|
+
project = null;
|
|
15712
|
+
}
|
|
15713
|
+
if (isWebProject(project)) {
|
|
15714
|
+
let url;
|
|
15715
|
+
try {
|
|
15716
|
+
const entry = await o.source.webEntry?.();
|
|
15717
|
+
url = entry?.url;
|
|
15718
|
+
} catch {
|
|
15719
|
+
url = void 0;
|
|
15720
|
+
}
|
|
15721
|
+
if (!url && o.source.key) {
|
|
15722
|
+
const file = project && typeof project.file === "string" ? String(project.file).trim().replace(/^\/+/, "") || "index.html" : "index.html";
|
|
15723
|
+
url = `${o.source.key.replace(/\/+$/, "")}/${file}`;
|
|
15724
|
+
}
|
|
15725
|
+
if (!url) throw new Error("网页壁纸:无法解析入口 URL(需要 Source.webEntry 或 httpSource)");
|
|
15726
|
+
return { ...base, type: "web", src: url, source: o.source };
|
|
15727
|
+
}
|
|
15728
|
+
const canvas = ensureSceneCanvas(el);
|
|
15729
|
+
return { ...base, type: "scene", canvas, source: o.source };
|
|
14351
15730
|
}
|
|
14352
|
-
function createScene(
|
|
15731
|
+
function createScene(el, options) {
|
|
14353
15732
|
const rt = createRuntime();
|
|
14354
15733
|
const events = { ready: [], error: [], diagnostic: [] };
|
|
14355
15734
|
let currentOptions = { ...options ?? {}, source: null };
|
|
15735
|
+
let boundEl = el;
|
|
14356
15736
|
const emitError = (err) => {
|
|
14357
15737
|
for (const fn of events.error) {
|
|
14358
15738
|
try {
|
|
@@ -14391,6 +15771,24 @@ function createScene(canvas, options) {
|
|
|
14391
15771
|
rt.onFirstFrame = () => {
|
|
14392
15772
|
rt.onFirstFrame = void 0;
|
|
14393
15773
|
prev?.();
|
|
15774
|
+
const info = rt.info ?? {
|
|
15775
|
+
width: 0,
|
|
15776
|
+
height: 0,
|
|
15777
|
+
layerCount: 0,
|
|
15778
|
+
hasModels: false,
|
|
15779
|
+
hasParticles: false,
|
|
15780
|
+
hasText: false
|
|
15781
|
+
};
|
|
15782
|
+
try {
|
|
15783
|
+
currentOptions.onReady?.(info);
|
|
15784
|
+
} catch {
|
|
15785
|
+
}
|
|
15786
|
+
for (const fn of events.ready) {
|
|
15787
|
+
try {
|
|
15788
|
+
fn(info);
|
|
15789
|
+
} catch {
|
|
15790
|
+
}
|
|
15791
|
+
}
|
|
14394
15792
|
resolve();
|
|
14395
15793
|
};
|
|
14396
15794
|
});
|
|
@@ -14404,7 +15802,9 @@ function createScene(canvas, options) {
|
|
|
14404
15802
|
return { promise, off };
|
|
14405
15803
|
};
|
|
14406
15804
|
const instance = {
|
|
14407
|
-
canvas
|
|
15805
|
+
get canvas() {
|
|
15806
|
+
return boundEl;
|
|
15807
|
+
},
|
|
14408
15808
|
pause() {
|
|
14409
15809
|
rt.paused = true;
|
|
14410
15810
|
rt.sceneCtl?.pause();
|
|
@@ -14423,11 +15823,13 @@ function createScene(canvas, options) {
|
|
|
14423
15823
|
},
|
|
14424
15824
|
setFps(fps) {
|
|
14425
15825
|
rt.cfg.sceneFps = fps;
|
|
15826
|
+
weShimCall(rt, (w) => w.__weSetFps?.(fps));
|
|
14426
15827
|
},
|
|
14427
15828
|
setVolume(volume) {
|
|
14428
15829
|
const v = Math.max(0, Math.min(1, volume));
|
|
14429
15830
|
rt.cfg.muted = v <= 0;
|
|
14430
15831
|
rt.sceneAudio?.setVolume(v);
|
|
15832
|
+
weShimCall(rt, (w) => w.__weSetVolume?.(v));
|
|
14431
15833
|
},
|
|
14432
15834
|
setRenderDpr(dpr) {
|
|
14433
15835
|
rt.cfg.renderDpr = dpr;
|
|
@@ -14444,17 +15846,17 @@ function createScene(canvas, options) {
|
|
|
14444
15846
|
async load(source) {
|
|
14445
15847
|
currentOptions = { ...currentOptions, source };
|
|
14446
15848
|
wireOptions(currentOptions);
|
|
14447
|
-
const cfg =
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
src: void 0,
|
|
14452
|
-
mediaBase: void 0
|
|
14453
|
-
};
|
|
15849
|
+
const cfg = await resolveMountConfig(boundEl, currentOptions);
|
|
15850
|
+
if (cfg.type === "scene" && cfg.canvas instanceof HTMLCanvasElement) {
|
|
15851
|
+
boundEl = cfg.canvas;
|
|
15852
|
+
}
|
|
14454
15853
|
rt.cfg = cfg;
|
|
14455
15854
|
rt.paused = false;
|
|
14456
15855
|
rt.info = void 0;
|
|
14457
15856
|
resetCoverAlign(rt);
|
|
15857
|
+
if (currentOptions.properties) {
|
|
15858
|
+
rt.liveUserProps = { ...currentOptions.properties };
|
|
15859
|
+
}
|
|
14458
15860
|
const firstFrame = armFirstFrame();
|
|
14459
15861
|
const failure = armFailure();
|
|
14460
15862
|
mountWallpaper(rt, cfg);
|
|
@@ -14498,10 +15900,17 @@ function createScene(canvas, options) {
|
|
|
14498
15900
|
const applyOptions = async (o) => {
|
|
14499
15901
|
currentOptions = o;
|
|
14500
15902
|
wireOptions(o);
|
|
14501
|
-
|
|
15903
|
+
const cfg = await resolveMountConfig(el, o);
|
|
15904
|
+
if (cfg.type === "scene" && cfg.canvas instanceof HTMLCanvasElement) {
|
|
15905
|
+
boundEl = cfg.canvas;
|
|
15906
|
+
}
|
|
15907
|
+
rt.cfg = cfg;
|
|
14502
15908
|
rt.paused = o.autoplay === false;
|
|
14503
15909
|
rt.info = void 0;
|
|
14504
15910
|
resetCoverAlign(rt);
|
|
15911
|
+
if (o.properties && Object.keys(o.properties).length) {
|
|
15912
|
+
rt.liveUserProps = { ...o.properties };
|
|
15913
|
+
}
|
|
14505
15914
|
const firstFrame = armFirstFrame();
|
|
14506
15915
|
const failure = armFailure();
|
|
14507
15916
|
mountWallpaper(rt, rt.cfg);
|
|
@@ -14516,8 +15925,8 @@ function createScene(canvas, options) {
|
|
|
14516
15925
|
instance.__applyOptions = applyOptions;
|
|
14517
15926
|
return instance;
|
|
14518
15927
|
}
|
|
14519
|
-
async function mount(
|
|
14520
|
-
const instance = createScene(
|
|
15928
|
+
async function mount(el, options) {
|
|
15929
|
+
const instance = createScene(el, options);
|
|
14521
15930
|
const withApply = instance;
|
|
14522
15931
|
await withApply.__applyOptions(options);
|
|
14523
15932
|
return instance;
|