@webwallgl/editor 3.0.2 → 3.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/package.json +2 -2
- package/types.d.ts +30 -0
- package/webwallgl-editor.mjs +87 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webwallgl/editor",
|
|
3
3
|
"description": "WebWallGL editor API: editable scene graph, picking, frame capture, .pkg export (superset of webwallgl)",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "oneincase <462534624@qq.com>",
|
|
7
7
|
"repository": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"webwallgl": "3.0
|
|
39
|
+
"webwallgl": "3.1.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
package/types.d.ts
CHANGED
|
@@ -378,6 +378,28 @@ export type MountOptions = {
|
|
|
378
378
|
* 只影响场景壁纸;网页壁纸本身就是页面脚本,不受此项控制。
|
|
379
379
|
*/
|
|
380
380
|
scripts?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* 网页壁纸 iframe 的沙箱级别。默认(缺省或 `"strict"`)= 仅 `allow-scripts`:
|
|
383
|
+
* 作者脚本拿不到宿主 origin,fetch/XHR 需要宿主返回 CORS 头,控制走 postMessage 通道。
|
|
384
|
+
* `"legacy"` = `allow-scripts allow-same-origin`,回到壁纸窗口旧行为 —— 只有素材
|
|
385
|
+
* 依赖同源身份(localStorage / 同源 fetch)时,嵌入方才能显式选它。
|
|
386
|
+
* 只影响网页壁纸;场景/媒体壁纸不受此项控制。详见 WallpaperConfig.webSandbox。
|
|
387
|
+
*/
|
|
388
|
+
webSandbox?: "strict" | "legacy";
|
|
389
|
+
/**
|
|
390
|
+
* 本机 WE 官方素材(安装目录 `assets/` 树)接入档位。缺省 = 按 URL 参数
|
|
391
|
+
* `?localAssets=` 解析,都没有时 dev 为 `"lazy"`、生产构建为 `"off"`(不发任何请求)。
|
|
392
|
+
* 显式传值优先于 URL 参数。档位:
|
|
393
|
+
* - `"off"`:关闭(缺省生产行为);
|
|
394
|
+
* - `"fonts"`:只开字体通路 —— 工坊文字层引用的 WE 内置字体(如
|
|
395
|
+
* `fonts/Segment7Standard.otf`)不在壁纸 pkg 里、只在官方 `assets/fonts`,
|
|
396
|
+
* 不开素材通路时只能静默回落 sans-serif(issue #24)。这一档只要素材根
|
|
397
|
+
* 可达就按名取字体,不连带开启公共贴图的批量装载(贴图继续走程序化复刻);
|
|
398
|
+
* - `"lazy"`:util 贴图急切 + particle/gradient 等按需 + 字体;
|
|
399
|
+
* - `"all"`:全量急切 + 字体(批量对账用,接受内存占用)。
|
|
400
|
+
* 素材根由嵌入方的 `/api/local-assets` 端点提供(官方树目录),库只按该约定发请求。
|
|
401
|
+
*/
|
|
402
|
+
localAssets?: "off" | "fonts" | "lazy" | "all";
|
|
381
403
|
/** 指针源。**当前未接线**,见 PointerSource 说明;外部喂指针请用 pushPointer() */
|
|
382
404
|
pointer?: PointerSource | null;
|
|
383
405
|
/**
|
|
@@ -405,6 +427,14 @@ export type MountOptions = {
|
|
|
405
427
|
* 实际生效值请读 `getQuality()`(返回的是生效值,可能已被自动降档改写)。
|
|
406
428
|
*/
|
|
407
429
|
autoQuality?: boolean;
|
|
430
|
+
/**
|
|
431
|
+
* 渲染过程渐显(**默认关**;仅 scene 壁纸):加载期渲染预览循环「边加载边画已就绪
|
|
432
|
+
* 图层」,画布 opacity 按「已完成贴图 job / 总 job」线性推进,终点 = 资源全部就绪
|
|
433
|
+
* (首帧时刻,即 `onReady` / mount() resolve 的那一拍)。失败/降级出口立即还原可见,
|
|
434
|
+
* 绝不把壁纸或兜底页吞成空白。纯函数见 `renderer/src/fade-in.ts`,接线见
|
|
435
|
+
* `scene-mount.ts` 渐显块;壁纸页对应 `?fadein=1`。
|
|
436
|
+
*/
|
|
437
|
+
fadeIn?: boolean;
|
|
408
438
|
/**
|
|
409
439
|
* 贴图烘焙(默认开):内嵌 PNG/JPEG 贴图的预缩放缓存。命中后省掉「解全尺寸再缩」
|
|
410
440
|
* (实测 −80% 解码耗时,缓存产物比原图小),像素与不烘时逐位一致;
|
package/webwallgl-editor.mjs
CHANGED
|
@@ -5642,6 +5642,18 @@ function parseTex(buf, opts = {}) {
|
|
|
5642
5642
|
const hasMipExtension = u32(buf, p);
|
|
5643
5643
|
p += 4;
|
|
5644
5644
|
if (freeImageFormat === FIF.UNKNOWN && hasMipExtension === 1) freeImageFormat = FIF.MP4;
|
|
5645
|
+
if (hasMipExtension > 1 && freeImageFormat !== FIF.MP4) {
|
|
5646
|
+
return parseConditionalTex(buf, {
|
|
5647
|
+
name,
|
|
5648
|
+
format,
|
|
5649
|
+
flags,
|
|
5650
|
+
textureWidth,
|
|
5651
|
+
textureHeight,
|
|
5652
|
+
containerMagic,
|
|
5653
|
+
freeImageFormat,
|
|
5654
|
+
start: p
|
|
5655
|
+
});
|
|
5656
|
+
}
|
|
5645
5657
|
containerVersion = hasMipExtension === 1 ? 4 : 3;
|
|
5646
5658
|
} else if (containerMagic === "TEXB0003\0") {
|
|
5647
5659
|
freeImageFormat = u32(buf, p) | 0;
|
|
@@ -5856,6 +5868,81 @@ function asciiTex(buf, start, len) {
|
|
|
5856
5868
|
for (let i = start; i < start + len; i++) s += String.fromCharCode(buf[i]);
|
|
5857
5869
|
return s;
|
|
5858
5870
|
}
|
|
5871
|
+
function parseConditionalTex(buf, opts) {
|
|
5872
|
+
const { name, format, flags, textureWidth, textureHeight, containerMagic, freeImageFormat, start } = opts;
|
|
5873
|
+
const at = (suffix) => name ? name + (suffix || "") : suffix || "tex";
|
|
5874
|
+
const found = findFreeImagePayload(buf, start);
|
|
5875
|
+
if (!found) throw new Error("条件变体纹理内未找到图像载荷: " + at(""));
|
|
5876
|
+
const width = found.width > 0 ? found.width : textureWidth;
|
|
5877
|
+
const height = found.height > 0 ? found.height : textureHeight;
|
|
5878
|
+
assertDims(width, height, at("[img0/mip0]"));
|
|
5879
|
+
return {
|
|
5880
|
+
format,
|
|
5881
|
+
formatName: TEXTURE_FORMATS[format] || String(format),
|
|
5882
|
+
flags,
|
|
5883
|
+
textureWidth,
|
|
5884
|
+
textureHeight,
|
|
5885
|
+
width,
|
|
5886
|
+
height,
|
|
5887
|
+
freeImageFormat,
|
|
5888
|
+
containerMagic,
|
|
5889
|
+
containerVersion: 3,
|
|
5890
|
+
isVideo: false,
|
|
5891
|
+
images: [[{ width, height, compression: 0, data: buf.subarray(found.offset, found.end) }]],
|
|
5892
|
+
frames: null
|
|
5893
|
+
};
|
|
5894
|
+
}
|
|
5895
|
+
function u32be(buf, o) {
|
|
5896
|
+
return (buf[o] << 24 | buf[o + 1] << 16 | buf[o + 2] << 8 | buf[o + 3]) >>> 0;
|
|
5897
|
+
}
|
|
5898
|
+
function isFreeImageAt(buf, i) {
|
|
5899
|
+
return buf[i] === 137 && buf[i + 1] === 80 && buf[i + 2] === 78 && buf[i + 3] === 71 || buf[i] === 255 && buf[i + 1] === 216 && buf[i + 2] === 255 || buf[i] === 71 && buf[i + 1] === 73 && buf[i + 2] === 70 && buf[i + 3] === 56 || buf[i] === 82 && buf[i + 1] === 73 && buf[i + 2] === 70 && buf[i + 3] === 70 && buf[i + 8] === 87 && buf[i + 9] === 69 && buf[i + 10] === 66 && buf[i + 11] === 80;
|
|
5900
|
+
}
|
|
5901
|
+
function findFreeImagePayload(buf, start) {
|
|
5902
|
+
const n = buf.length;
|
|
5903
|
+
for (let i = Math.max(0, start); i + 12 < n; i++) {
|
|
5904
|
+
if (!isFreeImageAt(buf, i)) continue;
|
|
5905
|
+
if (buf[i] === 137 && buf[i + 1] === 80 && buf[i + 2] === 78 && buf[i + 3] === 71) {
|
|
5906
|
+
const w = u32be(buf, i + 16);
|
|
5907
|
+
const h = u32be(buf, i + 20);
|
|
5908
|
+
let q2 = i + 8;
|
|
5909
|
+
while (q2 + 8 <= n) {
|
|
5910
|
+
const len = u32be(buf, q2);
|
|
5911
|
+
const isIend = buf[q2 + 4] === 73 && buf[q2 + 5] === 69 && buf[q2 + 6] === 78 && buf[q2 + 7] === 68;
|
|
5912
|
+
if (len > n || q2 + 12 + len > n) break;
|
|
5913
|
+
q2 += 12 + len;
|
|
5914
|
+
if (isIend) break;
|
|
5915
|
+
}
|
|
5916
|
+
return { offset: i, end: Math.min(q2, n), width: w, height: h };
|
|
5917
|
+
}
|
|
5918
|
+
if (buf[i] === 82 && buf[i + 1] === 73 && buf[i + 2] === 70 && buf[i + 3] === 70) {
|
|
5919
|
+
const size = buf[i + 4] | buf[i + 5] << 8 | buf[i + 6] << 16 | buf[i + 7] << 24;
|
|
5920
|
+
return { offset: i, end: Math.min(i + 8 + size, n), width: 0, height: 0 };
|
|
5921
|
+
}
|
|
5922
|
+
if (buf[i] === 71 && buf[i + 1] === 73 && buf[i + 2] === 70) {
|
|
5923
|
+
const w = buf[i + 6] | buf[i + 7] << 8;
|
|
5924
|
+
const h = buf[i + 8] | buf[i + 9] << 8;
|
|
5925
|
+
let end = n;
|
|
5926
|
+
for (let j = i + 10; j + 4 < n; j++) {
|
|
5927
|
+
if (isFreeImageAt(buf, j)) {
|
|
5928
|
+
end = j;
|
|
5929
|
+
break;
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
return { offset: i, end, width: w, height: h };
|
|
5933
|
+
}
|
|
5934
|
+
let q = i + 2;
|
|
5935
|
+
while (q + 1 < n) {
|
|
5936
|
+
if (buf[q] === 255 && buf[q + 1] === 217) {
|
|
5937
|
+
q += 2;
|
|
5938
|
+
break;
|
|
5939
|
+
}
|
|
5940
|
+
q++;
|
|
5941
|
+
}
|
|
5942
|
+
return { offset: i, end: Math.min(q, n), width: 0, height: 0 };
|
|
5943
|
+
}
|
|
5944
|
+
return null;
|
|
5945
|
+
}
|
|
5859
5946
|
function resampleRgba(src, w2, h2) {
|
|
5860
5947
|
const { width: w, height: h, rgba } = src;
|
|
5861
5948
|
const W = Math.max(1, Math.round(w2));
|