@webwallgl/core 3.0.2 → 3.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webwallgl/core",
3
3
  "description": "WebWallGL engine core: Wallpaper Engine .pkg / .tex decoding and fit math (zero dependencies)",
4
- "version": "3.0.2",
4
+ "version": "3.0.3",
5
5
  "license": "MIT",
6
6
  "author": "oneincase <462534624@qq.com>",
7
7
  "repository": {
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
  /**
@@ -475,6 +475,18 @@ function parseTex(buf, opts = {}) {
475
475
  const hasMipExtension = u32(buf, p);
476
476
  p += 4;
477
477
  if (freeImageFormat === FIF.UNKNOWN && hasMipExtension === 1) freeImageFormat = FIF.MP4;
478
+ if (hasMipExtension > 1 && freeImageFormat !== FIF.MP4) {
479
+ return parseConditionalTex(buf, {
480
+ name,
481
+ format,
482
+ flags,
483
+ textureWidth,
484
+ textureHeight,
485
+ containerMagic,
486
+ freeImageFormat,
487
+ start: p
488
+ });
489
+ }
478
490
  containerVersion = hasMipExtension === 1 ? 4 : 3;
479
491
  } else if (containerMagic === "TEXB0003\0") {
480
492
  freeImageFormat = u32(buf, p) | 0;
@@ -689,6 +701,81 @@ function asciiTex(buf, start, len) {
689
701
  for (let i = start; i < start + len; i++) s += String.fromCharCode(buf[i]);
690
702
  return s;
691
703
  }
704
+ function parseConditionalTex(buf, opts) {
705
+ const { name, format, flags, textureWidth, textureHeight, containerMagic, freeImageFormat, start } = opts;
706
+ const at = (suffix) => name ? name + (suffix || "") : suffix || "tex";
707
+ const found = findFreeImagePayload(buf, start);
708
+ if (!found) throw new Error("条件变体纹理内未找到图像载荷: " + at(""));
709
+ const width = found.width > 0 ? found.width : textureWidth;
710
+ const height = found.height > 0 ? found.height : textureHeight;
711
+ assertDims(width, height, at("[img0/mip0]"));
712
+ return {
713
+ format,
714
+ formatName: TEXTURE_FORMATS[format] || String(format),
715
+ flags,
716
+ textureWidth,
717
+ textureHeight,
718
+ width,
719
+ height,
720
+ freeImageFormat,
721
+ containerMagic,
722
+ containerVersion: 3,
723
+ isVideo: false,
724
+ images: [[{ width, height, compression: 0, data: buf.subarray(found.offset, found.end) }]],
725
+ frames: null
726
+ };
727
+ }
728
+ function u32be(buf, o) {
729
+ return (buf[o] << 24 | buf[o + 1] << 16 | buf[o + 2] << 8 | buf[o + 3]) >>> 0;
730
+ }
731
+ function isFreeImageAt(buf, i) {
732
+ 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;
733
+ }
734
+ function findFreeImagePayload(buf, start) {
735
+ const n = buf.length;
736
+ for (let i = Math.max(0, start); i + 12 < n; i++) {
737
+ if (!isFreeImageAt(buf, i)) continue;
738
+ if (buf[i] === 137 && buf[i + 1] === 80 && buf[i + 2] === 78 && buf[i + 3] === 71) {
739
+ const w = u32be(buf, i + 16);
740
+ const h = u32be(buf, i + 20);
741
+ let q2 = i + 8;
742
+ while (q2 + 8 <= n) {
743
+ const len = u32be(buf, q2);
744
+ const isIend = buf[q2 + 4] === 73 && buf[q2 + 5] === 69 && buf[q2 + 6] === 78 && buf[q2 + 7] === 68;
745
+ if (len > n || q2 + 12 + len > n) break;
746
+ q2 += 12 + len;
747
+ if (isIend) break;
748
+ }
749
+ return { offset: i, end: Math.min(q2, n), width: w, height: h };
750
+ }
751
+ if (buf[i] === 82 && buf[i + 1] === 73 && buf[i + 2] === 70 && buf[i + 3] === 70) {
752
+ const size = buf[i + 4] | buf[i + 5] << 8 | buf[i + 6] << 16 | buf[i + 7] << 24;
753
+ return { offset: i, end: Math.min(i + 8 + size, n), width: 0, height: 0 };
754
+ }
755
+ if (buf[i] === 71 && buf[i + 1] === 73 && buf[i + 2] === 70) {
756
+ const w = buf[i + 6] | buf[i + 7] << 8;
757
+ const h = buf[i + 8] | buf[i + 9] << 8;
758
+ let end = n;
759
+ for (let j = i + 10; j + 4 < n; j++) {
760
+ if (isFreeImageAt(buf, j)) {
761
+ end = j;
762
+ break;
763
+ }
764
+ }
765
+ return { offset: i, end, width: w, height: h };
766
+ }
767
+ let q = i + 2;
768
+ while (q + 1 < n) {
769
+ if (buf[q] === 255 && buf[q + 1] === 217) {
770
+ q += 2;
771
+ break;
772
+ }
773
+ q++;
774
+ }
775
+ return { offset: i, end: Math.min(q, n), width: 0, height: 0 };
776
+ }
777
+ return null;
778
+ }
692
779
  const DESIGN_ASPECTS = [
693
780
  [16, 9],
694
781
  [16, 10],